wp_send_json()
wp_send_json( mixed $response, int $status_code = null …
wp_send_json( mixed $response, int $status_code = null )
将JSON响应发送回Ajax请求。
Send a JSON response back to an Ajax request.
目录锚点:#参数#源码#笔记
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $response | (mixed) | 变量(通常是数组或对象)以编码为JSON,然后打印并消亡。 |
| $status_code | (int) | 要输出的HTTP状态代码。 |
源码(Source)
/**
* Send a JSON response back to an Ajax request.
*
* @since 3.5.0
*
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
*/
function wp_send_json( $response ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
echo wp_json_encode( $response );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
wp_die();
else
die;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.7.0 | wp-includes/functions.php | 4 | 1 |
笔记(Notes)
注意:使用wp_send_json()后不需要包含wp_die()或exit(0),因为它会自动调用wp_die()。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!