用ajax beforeSend修改数据数据、ajax、beforeSend

由网友(丶男生的痛只有自己懂。)分享简介:比方说,我有jQuery的Ajax调用是这样的:Let's say I have an Ajax call from jQuery like this: $.ajax({url: myUrl,data: myData,type:'post'});我希望能够用添加到myData的I would like to b...

比方说,我有jQuery的Ajax调用是这样的:

Let's say I have an Ajax call from jQuery like this:

$.ajax({
   url: myUrl,
   data: myData,
   type:'post'
});

我希望能够用添加到myData的

I would like to be able to add to the myData using

$.ajaxSetup({
   beforeSend: function(call){...}
});

结果应该是所有Ajax调用(POST和GET)被修改,所以,如果我得到一个额外的参数IsAjax =真

The result should be that all ajax calls (both post and get) is modified so if i get an extra parameter IsAjax=true

推荐答案

This博客文章解释了如何使用 $。ajaxSetup 添加数据。它积累了像 $。延长 只要做到这一点:

This blog post explains how you can use $.ajaxSetup to add data. It accumulates like $.extend Just do this:

$.ajaxSetup({
  data:{
    isAjax:true
  }
});
阅读全文

相关推荐

最新文章