我有一个类似这样的 AJAX 响应。
[{"label":"label","label1":"67041","label2":"745","label3":"45191","label4":"11464"}]<table id="table"></table>
响应中同时包含 JSON 和 HTML。
我想将这两件事分开。
并将 JSON 用于我创建的图表函数。
然后将该表附加到 div
中。
任何建议都会非常富有成效。
提前致谢。
最佳答案
在 PHP 中
$array = 'Your json array';
$html = 'Your html codes';
使用两个键创建一个数组
$newArray = array();
$newArray['json'] = $array;
$newArray['html'] = $html;
echo json_encode($newArray);
在 Jquery 中
DataType: 'JSON',
success:function(response){
response.json = 'This is your json';
response.html = 'This is your html';
}
关于javascript - jquery - 将 JSON 和 HTML 从 AJAX 响应中分离出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310195/