PHP trigger AJAX error code without using array

前端 未结 4 2180
迷失自我
迷失自我 2021-01-06 08:33

I want to be able to get a PHP script called via AJAX to return with an error code that the jQuery AJAX handler error: will handle. I don\'t want to use a JSON

4条回答
  •  旧巷少年郎
    2021-01-06 09:04

    EDIT: jQuery'ajax'statusCode' method works, but only in jQuery 1.5

    I have tried jquery's ajax's 'statusCode' method, works now, with jquery 1.5 but did not get any results... but it should be the way to go...

    if my php script does this:

     //localhost/dev/false.php
     header("HTTP/1.0 404 Not Found");  
     exit();
    

    and my javascript does that:

    $.ajax({
      url:'http://localhost/dev/false.php',
      statusCode: {
                      404: function() {
                          alert('page not found');
                      }
                  }
              });
    

提交回复
热议问题