当前位置:Gxlcms > PHP教程 > $.ajax为什么自定义的options无法传进去给回调

$.ajax为什么自定义的options无法传进去给回调

时间:2021-07-01 10:21:17 帮助过:8人阅读

$.ajax为什么自定义的options无法传进去给回调????

  1. //单击执行AJAX请求操作function clickSubmit(sendUrl, data, _sucmsg, _errmsg){
  2. $.ajax({
  3. type: "POST",
  4. url: sendUrl,
  5. dataType: "json",
  6. timeout: 20000,
  7. data: data,
  8. sucmsg: _sucmsg,
  9. //????????????????????????
  10. errmsg: _errmsg, //????????????????????????
  11. success: function(data, textStatus) {
  12. if (data.status == 1){
  13. $.dialog.tips(this.sucmsg ? this.sucmsg : data.msg, 2, "32X32/succ.png", function(){
  14. //location.reload();
  15. });
  16. } else {
  17. $.dialog.alert(this.errmsg ? this.errmsg : data.msg);
  18. }
  19. },
  20. error: function (XMLHttpRequest, textStatus, errorThrown) {
  21. $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown);
  22. }
  23. });}


回复讨论(解决方案)

可以的!
你看看回调函数的 data 参数是什么

  1. //单击执行AJAX请求操作function clickSubmit(sendUrl, data, _sucmsg, _errmsg){
  2. $.ajax({
  3. type: "POST",
  4. sucmsg: _sucmsg,
  5. //????????????????????????
  6. errmsg: _errmsg, //????????????????????????
  7. success: function(data, textStatus) {
  8. alert(this.type); //////////弹出type alert(this.sucmsg);//弹出未定义,说明jquery.ajax的options不能自定义自己的
  9. }
  10. });}




应该是你的参数 _sucmsg 没有传入

晕。真行啊。昨晚不知哪弄错。

人气教程排行