j-man86 j-man86 - 1 year ago 80
PHP Question

Getting ajax post data on success

I have the following ajax call. What I would like to do is set the variable "lan_setting" during the ajax requests, and be able to use that variable on success.

In reality I want to set that variable to be post data, which will vary depending on the form input, but as of now I can't even get it working with just this basic example. It just returns "undefined".

_jqXHR = $.ajax({
url: url,
data: {lan_setting: 'en'},
scriptCharset: "UTF-8",
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
success: function(lan_setting, data, textStatus, jqXHR) {

How do I can I use post variable sent via ajax on success?


Answer Source

Well, if you're posting, you should use the jquery post function here

    function( data, status, jqXhr ){

then php:

    // do stuff

    $response = new stdClass;
    $response->lan_setting = $_POST["lan_setting"];
    print json_encode($response);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download