jsp页面中的ajax:
$(document).ready(function (){
$.ajax({
url:'AjaxServlet',
url:'http:192.168.10.2/jspTophp.php';
type:"POST",
dataType:'json',
data:"act=testid",
success:function(data){
$(data).each(function(){
var eid=$(this).attr("eid");
$("#testid").append("<option value="+eid+">"+eid+"</option>");
})
}
}),
error:function(){
alert("error!");
};
php页面:
<?php
#
#
require("defs.php3");
$result = DBQueryFatal("select eid,start_time,end_time from testbed_history");
$jsonarr=array();
$i=0;
while ($row = mysql_fetch_array($result))
{
$eid = $row["eid"];
$start_time=$row["start_time"];
$end_time=$row["end_time"];
$jsonarr[$i]=array('eid'=> $eid,'start_time'=> $start_time,'end_time'=> $end_time);
$i++;
}
$json_str=json_encode($jsonarr);
echo $json_str;
?>
jsp页面上的ajax执行了error:function
都是基于http协议,所以请求php是可以的。你这个问题应该属于跨域访问,所以需要通过JSONP来进行访问。
dataType:"jsonp",
jsonp:"jsonpcallback",
可以参考一下下面的例子:
[url]http://aijezdm915.iteye.com/blog/1066299[/url]
是不是跨域的问题?