简体   繁体   English

下一个jQuery代码有什么问题?

[英]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). 代码的一部分/ publications / deleteItem /'+ valueClicked可以,我检查了(正确删除了正确的项目)。

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... 因此,alert('602!')永远不会消失...

There's nothing wrong with this jQuery code. jQuery代码没有错。 The server simply didn't return a HTTP 2nn or 3nn response, but a 4nn or 5nn response. 服务器只是没有返回HTTP 2nn或3nn响应,而是4nn或5nn响应。 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. 您可以使用Firebug的网络”面板检查响应标头和状态。

open up the net panel in firebug and look at the response codes. 在Firebug中打开网络面板,然后查看响应代码。 successful response codes are 2xx or 3xx. 成功的响应代码是2xx或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. 由于您尝试创建REST接口,因此首先应该测试直接调用您要执行的操作。

Let's imagine you domain is: http://www.mydomain.com 假设您的域名是: http : //www.mydomain.com

Try to call http://www.mydomain.com/publications/deleteItem/123456 and see what is returned from the server. 尝试调用http://www.mydomain.com/publications/deleteItem/123456 ,查看服务器返回了什么。 The most probably your server is doing a redirect or outputting some error,and that's the source of your problem. 您的服务器很可能正在执行重定向或输出一些错误,这就是问题的根源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM