0

I have following bit of code which I am tring to run

   $.ajax({
      cache: false,
      url: './animationPlay.php',
      data: 'animation='+text,
      type: 'POST',
      datatype: 'text',
      success: function(data) { alert("succsess") },
      error: function(ts) { alert('error:'+ts.responseText) }
   });

I have seen how to catch ajax query post error? and jQuery $.get or $.post to catch page load error (eg. 404) but it doesn't work for my code.It is simply set to "error". How do I get more detail about what's gone wrong?

Thanks in advance.

EDIT: I tried

error: function(xhr, textStatus, error){
  console.log(xhr.statusText);
  console.log(textStatus);
  console.log(error);
}

I got error, error, an empty string in console. What does it mean?

Community
  • 1
  • 1
Apb
  • 979
  • 1
  • 8
  • 25

4 Answers4

0

Try this ::

$.ajax({
        cache: false,
        url: './animationPlay.php',
        data: {
            animation: text
        },
        type: 'POST',
        datatype: 'text',
        success: function(data) { alert("succsess") },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText);
        }
Tushar Trivedi
  • 400
  • 1
  • 2
  • 12
  • 1
    this may help with your 0 status code issue: http://stackoverflow.com/questions/2000609/jquery-ajax-status-code-0 – jjenzz Apr 15 '13 at 13:41
-1

Try sending the post data as an object...

$.ajax({
    cache: false,
    url: './animationPlay.php',
    data: {
        animation: text
    },
    type: 'POST',
    success: function(data) { alert("succsess") },
    error: function(ts) { alert('error:'+ts.responseText) }
});
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
-1
$.ajax({
      cache: false,
      url: './animationPlay.php',
      data: 'animation='+text,
      type: 'POST',
      dataType: 'text',
      success: function(data) { alert("succsess") },
      error: function(ts) { alert('error:'+ts.responseText) }
      contentType:'SET THE CONTENT TYPE'
   });

Check for existense of the URL

Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
-1

Try this:

$.ajax({
        cache: false,
        url: 'animationPlay.php',
        data:  text,
        type: 'POST',
        dataType: 'text',       //<== see, in your question's code you have small 't'
        success: function(data) { alert("succsess") },
        error: function(){
            alert('error');
        }
user1740381
  • 2,121
  • 8
  • 37
  • 61