ajax in function, with custom parameter for persistance

ajax in function, with custom parameter for persistance

If you embed an ajax call in a function, and want to pass some value to that ajax-call as a function parameter, then you can store that value into a custom parameter in de ajax object, and assess its value as this.myvar in the success function.

    function test_ajax(myvalue) {
        jQuery.ajax({
          url: 'main_ajax.aspx'
           ,success: function() {
                    alert( 'success ' + this.myvar );
                 }
           ,myvar: myvalue
        });
    }

    test_ajax('some_value');