开发者

Difference between response of -1 and 0 for wordpress plugin ajax call

What is the difference between a response of -1 and 0 with a wordpress ajax plugin?

http://codex.wordpress.org/AJAX_in_Plugins

The documentation states:

Error Return Values

If the AJAX request fails when the request url is wp-admin/admin-ajax.php, it will return either -1 or 开发者_运维问答0 depending on the reason it failed.

But that's a pretty basic answer and it doesn't state what situations would trigger either type of error. Anyone have any idea?


You get a -1 when when you have an authentication-related issue:

  • The current user is not logged in, or does not have permissions to do some sort of requested action.
  • There is no requested action posted, or the posted action is not found.

I believe a return of 0, or 1, is used as a boolean false/true (respectively) return.

If you're asking because you're using this for your plugin, I highly advise you use JSON, and return something like {success: true} that way your code KNOWS that there was a valid response, and anything other than a valid JSON response I would consider as a failure.

Also don't forget to use wp_ajax_ and wp_ajax_nopriv_ for your API added actions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜