JQuery $ .ajaxSend () settings.data is null

I found a strange bug (maybe). When I send parameters to $ .ajax in hash form and try to check those parameters in $ .ajaxSend, I found that settings.data is null, settings.url was fine with options enabled. Then I go through the jQuery code and find that the data is erased.

    // If data is available, append data to url for get requests
    if ( s.data && type == "GET" ) {
        s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;

        // IE likes to send both get and post data, prevent this
        s.data = null;
    }

      

Now I need to parse the url ((.) What should I do?

In JQuery, using ajaxSend to preview url built by calling $ .post

Here in the comments I see that the data should be there.

+1


source to share


1 answer


By default, all data passed as non-string data is processed and converted to a query string. So, if you use POST to skip the error:

 $.post({
      url: "http://yourserver/ajax" ,
      data: {param1: 'val1', param2:'val2'}
 });

      

into the $.ajaxSend

value settings.data

will be 'param1=val1&param2=val2'

and you will need to parse the parameters, for example using GET.



If you want to avoid parsing the URL or data, just add a copy of the data when you create the settings object. The optional parameter shouldn't cause any problems.

 var data = {param1: 'val1', param2:'val2'};
 $.get({
      url: "http://yourserver/ajax" ,
      data: data,
      dataCopy: data
 });

      

Then in $.ajaxSend

you can check the values ​​in settings.dataCopy

.

+1


source