tags:

views:

53

answers:

4

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...

+2  A: 

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.

BalusC
can i somehow make that it always return 'success'?
You can do that by ensuring that the HTTP response status is 2nn or 3nn. A normal success response code is 200. This is the default when your PHP code runs without errors/dies/wrong-redirects/etc.
BalusC
+1  A: 

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);
},
Moin Zaman
+1  A: 

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.

João Gala Louros
A: 

I see that you are using a POST instead of a GET. What data are your POSTing to the url ?

letronje
It's fair enough to make a destructive action like delete require a post, even if there is no post data. There are horror stories about web spiders following delete links...
Douglas