发送前是否需要对ajax响应数据进行json_encode?
$html1 = '<span>some html</span>';
$html2 = '<span>some html</span>';
$res = array('html1'=>$html1, 'html2'=>$html2);
echo json_encode($res);
或
echo $res;
AJAX中的X代表XML
如果返回XHTML,则不需要对其进行json_encode
echo '<div>'.$html1.$html2.'</div>';
你可以
将其转储到页面
someElement.innerHTML = returnValue;
或document.body.insertAdjacentHTML('afterend',returnValue);
从DOMFragment提取:
const domFragMent = document.createElement("div")
domFragment.innerHTML = returnValue;
const spans = domFragment.querySelectorAll("span");
使用domParser
发送一个json_encoded值数组,并在客户端上将其解析为跨度