如何在网页中执行AJAX响应返回的javascript(response=html+;javascript)
当我将url设置为buyresult.php?q=myStore时,我的buyresult.php页面工作正常 但是我在ajax调用后得到的响应(html和javascript都是响应)。。javascript不工作。。。如何解决这个问题。。我是网络编程新手。请帮忙。。 我在谷歌上搜索了一下,得到了使用的结果如何在网页中执行AJAX响应返回的javascript(response=html+;javascript),javascript,html,ajax,Javascript,Html,Ajax,当我将url设置为buyresult.php?q=myStore时,我的buyresult.php页面工作正常 但是我在ajax调用后得到的响应(html和javascript都是响应)。。javascript不工作。。。如何解决这个问题。。我是网络编程新手。请帮忙。。 我在谷歌上搜索了一下,得到了使用的结果 new Ajax.Updater(divID,URL,{asynchronous:true,evalScripts: true}); 但是我不知道把这个函数放在哪里 我的index.ph
new Ajax.Updater(divID,URL,{asynchronous:true,evalScripts: true});
但是我不知道把这个函数放在哪里
我的index.php文件如下所示:
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","buyresult.php?q="+str,true);
xmlhttp.send();
}
}
</script></head>
<body>
<label for="city">Enter City :</label><input class="w-input" id="city" type="text" placeholder="Enter the city name (required)" name="city" data-name="city" required="required" onchange="showUser(this.value)">
<div id="txtHint"><b>Results will be displayed Here...</b></div>
</body>
函数showUser(str){
如果(str==“”){
document.getElementById(“txtHint”).innerHTML=“”;
回来
}否则{
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}否则{
//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“buyresult.php?q=“+str,true”);
xmlhttp.send();
}
}
进入城市:
结果将显示在这里。。。
也许您可以尝试使用一个库来帮助进行常见的javascript操作。最著名的一个例子是:我不知道jquery。。怎样才能做到呢?