私たちが知っているように、AJAX はサーバーから HTML 形式の Web パーツを要求するために使用されます。AJAX を使用した関数を含むスクリプトを要求することはできますか?
3 に答える
1
必要なことを達成するためにeval()を使用する方法の例を次に示します。
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
eval(xmlhttp.responseText);
// you can use whatever functionw as returned from the server from this line on :)
}
}
xmlhttp.open("GET","your-server-page-url",true);
xmlhttp.send();
于 2013-09-06T08:34:46.993 に答える