$。阿贾克斯()成功,将无法运行功能 [英] $.ajax() success won't run function

查看:132
本文介绍了$。阿贾克斯()成功,将无法运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题关于 $。阿贾克斯() jQuery的方法。我不能在 $成功参数。阿贾克斯()工作。

My question regards the $.ajax() jQuery method. I can't get the success parameter in $.ajax() to work.

本作品:

              $.ajax({
                    type: 'POST',
                    url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
                    dataType: 'json',
                    success: window.alert("inside aJax statement")

                     });

这不:

         $.ajax({
                    type: 'POST',
                    url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
                    dataType: 'json',
                    success: function(){
                        window.alert("inside aJax statement");
                        }                       
                     }); 

在第一种情况下,我得到的,让我知道了 $。AJAX一个JavaScript警告窗口()我打电话给正在工作。所有这一切都在code为我把 window.alert() A 函数内部(){window.alert第二块变(); }

In the first case, I get a JavaScript alert window that lets me know the $.ajax() I called is working. All that is changed in the second block of code is I put the window.alert() inside a function() { window.alert(); }.

这样做的一点是要验证$就运行这样我就可以把一些实际有用的code。在函数(){} 当$就成功运行。

The point of this is to verify that the $.ajax is running so I can put some actual useful code in the function(){} when the $.ajax runs successfully.

推荐答案

在你的第二个例子什么也不会发生。添加一个错误回调因为这里许多人建议看,确实Ajax请求的工作,但服务器当前未发送有效的响应。

In your second example nothing will happen unless you get a successful call back from the server. Add an error callback as many here have suggested to see that indeed the ajax request is working but the server is not currently sending a valid response.

$.ajax({
        type: "POST",
        url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),                        
        dataType:"json",
        success: function(response){
                alert(response);        
      },
      error: function(jqXHR, textStatus, errorThrown){
          alert('error');
      }         
      });

在跟踪误差有帮助链接

这篇关于$。阿贾克斯()成功,将无法运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆