Is it possible to modify the data sent in an Ajax request by modifying the XMLHttpRequest object in the beforeSend callback? and if so how might I do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can modify it, the signature of
beforeSendis actually (in jQuery 1.4+):even though the documentation has just
beforeSend(XMLHttpRequest), you can see how it’s called here, wheresis the settings object:So, you can modify the
dataargument before then (note that it’s already a string by this point, even if you passed in an object). An example of modifying it would look like this:If it helps, the same signature applies to the
.ajaxSend()global handler (which does have correct documentation showing it), like this: