j-man86 j-man86 - 5 months ago 26
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?



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);