大家好!
我想知道是否有可能调用php脚本运行使用jQuery的asp.net应用程序(Win7,VS2010,IIS)?我尝试了一些不同的教程,其中一个设置如下:
My jQuery ajax-call:
$.ajax(
{
post: "GET",
url: "js/script.php"
}).done(function (data) {
alert(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
});
我的php脚本:
<?php echo '<div id="test">Hello, World!</div>';?>
调用ajax函数只是警告原始php脚本文本,即
"<?php echo '<div id="test">Hello, World!</div>';?>"
不影响其他任何事
我做错了什么?我已经明白,它应该是有可能在asp服务器上运行这个。
(PS。当我发布这篇文章时,我已经研究了建议的主题,但没有人写过他们得到实际的php-text返回DS。
你不能在没有安装PHP的"ASP-Server"上运行PHP脚本。安装PHP,一切都将正常运行。
手册可能在php.net.
必须在ajax调用中指定数据类型。
如果你没有看到任何东西,请在控制台查看从调用中检索到的一些错误
试试这个:
$.ajax(
{
post: "GET",
url: "js/script.php",
dataType : 'html'
}).done(function (data) {
alert(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
});
在执行PHP脚本时获取原始PHP。这仅仅意味着由于某些原因你的PHP没有被解释。
检查php服务器是否安装和配置正确
这里有一些东西可以帮助你
function showState(str){
if(str.length==0){
document.getElementById("country").innerHTML="";
return;
}
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request");
return;
}
var url="request.php";
url +="?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("state").innerHTML=xmlHttp.responseText;
}
}
<select name="country" id="country" onchange="showState(this.value)">
<option value="0">ChooseProject</option>
<c:forEach items="${al }" var="v">
<option value="${v.projectid}">${v.projectname}</option>
</c:forEach>
</select>