开发者

What is wrong with next jQuery code?

can you help开发者_如何学编程 me why it returns error.

part of code /publications/deleteItem/' + valueClicked works ok, i checked (proper item is properly deleted).

var valueClicked = 123456;
$.ajax({
    type: "post",
    url: '/publications/deleteItem/' + valueClicked, // 100% works!
    success: function(xml) {
        alert('602!');
    }, 
    error:function (XMLHttpRequest, textStatus, errorThrown) {
        alert(errorThrown); // throwns undefined?!
    }

});

so, alert('602!') never exetutes...


There's nothing wrong with this jQuery code. The server simply didn't return a HTTP 2nn or 3nn response, but a 4nn or 5nn response. This will cause the error handler being invoked instead of the success handler.

You can use Firebug's Net panel to check the response headers and the status.


open up the net panel in firebug and look at the response codes. successful response codes are 2xx or 3xx.

also try changing the success and error callbacks as follows and report back what you get.

success:function(data, status, xml) {
    alert(status);
},
error:function(data, status, xml) {
    alert(status);
},


Since you are trying to create a REST interface you should test direct calls for what do you want to do in the first place.

Let's imagine you domain is: http://www.mydomain.com

Try to call http://www.mydomain.com/publications/deleteItem/123456 and see what is returned from the server. The most probably your server is doing a redirect or outputting some error,and that's the source of your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜