JQuery injecting data into ajax global event

I am trying to insert data into my ajax requests, but it fails and I don't know why. I tried to look at the jQuery source code, but still can not find why it does not work. Any help appreciated. Here is the code:

$('#someElement').ajaxSend(function(e, req, options) {
    options.data += (options.data.length > 0 ? '&' : '') + '__token=' + $('input#requestToken').val();
}).ajaxSuccess(function(e, req, options, data) {
    if (data.nextToken) {
        $('input#requestToken').val(data.nextToken);
        delete data.nextToken;
    }
});

The answer is as follows:

{
   "response":
   {
      "code":0,
      // ...
   },
   "nextToken":"4ded26352b3d44"
}

A typical query would be, for example:

$.getJSON(url, {something:'value'}, function(data) {
   if (data.response.code != 0) {
      // handle code
   }
});

The problem is that the data sent is " something=value"; Modified is datanot sent.

** EDIT **

Current request data

something: value

and should be

something: value
__token: 4ded288eec1f56

In the event callback ajaxSend, if after changing it I print the value options.data, the value will be " something=value&__token=4ded288eec1f56", but " __token=4ded288eec1f56" not sent . Why is it not sent in the request?

, "" , ?

+3
4

, , , jQuery ajaxSend, . , .

edit — @mikermcneil, , . jQuery "ajax", , . , , , , , , jQuery: -)

+2

-edit

- getJSON.

, jQuery ajaxSend , getJSON, .

getJSON $.post, ( , ).

-edit- , :

http://abolition.me/toys/View/attachAjax.html (. )

, , , : __token: "toketoketoke" : "val1" key2: "val2"

, , - ?

- ( , ), , , ? ($ (function() {});)

+2

, JSON :

{
  "response":
  {
  "code":0,  <-- this is not valid
  },
  "nextToken":"4ded26352b3d44"
}

:

{
  "response":
  {
  "code":0
  },
  "nextToken":"4ded26352b3d44"
}

JSON, :

JSON

0

You only pass data in the second parameter in your call to getJSON {something: 'value'}. Any data that you want to send to the server should be included there. Therefore, __token should be included in this parameter.

The third parameter in the getJSON call is the callback function. The parameter passed to this function is the response from the server.

$.getJSON(
    url,
    {
        something:'value',
        __token: 'token value'
    ,
    function(response) {
        if (response.response.code != 0) {
        // handle code
        }
    }
);
0
source

All Articles