新手问题 ajax 高人快来,新手 $.ajax 调试晕菜了

lotusroot · May 22, 2014 · Last by lotusroot replied at May 23, 2014 · 2389 hits

请问有啥办法能够调试$.ajax 调用的整个过程(包括能够跟踪进 controller)?

现在光是看 error:function(msg) 报错 [object Object],不晓得错在哪里:是 url 没写对?是 data 没写对?还是别的啥没写对?

$.ajax({
      url: "/some/path", 
      type: 'POST',
      data: $( "#form" ).serialize()})
      .done(function( data ) {
        ......; 这个data 是controller返回的比如 render text: 'ok'data就是ok
      })
      .fail( function( xhr, status ) {
        alert( xhr.responseText );
      });

其他方法查 $.ajax 吧。

$.ajax({ ... })
      .done( ... )
      .fail( ... );

简单的写,是这样的。

这样的描述别说高人,神仙也救不了

打开 Chrome 的 Developer Tools 或 Firefox 的 firebug 看一下网络请求就知道了。

chrome 下,试试看用console.log(object) 打出来可以看到 object 里面的内容

用 Chrome. 里面自带 debug 工具。还能设 breakpoint

已经发现了一个问题,url 里少写了个/,其他问题继续扫雷中,新手对一些简单问题也觉得高深莫测 ^_^

You need to Sign in before reply, if you don't have an account, please Sign up first.