PHP trigger AJAX error code without using array

前端 未结 4 2174
迷失自我
迷失自我 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:19

    If you want to trigger the AJAX error handler, just pass back something other than a 200! Try this:

    
    

    Just remember to do two things:

    1. Try to send the correct error code to comply with HTTP methods. i.e. if you page throws an error, then you should return a 500, etc. You can see a reference here at the w3.org site.
    2. Make sure you send the header before ANY other content except whitespace.

    This should be the clean solution you are going for.

提交回复
热议问题