当我尝试使用JQuery从本地主机调用位于远程when服务器上的php文件时,下面的wamp方法无法工作。但是,如果它们都位于同一台they服务器上,就可以正常工作。我相信我已经打开了crossDomain,还不能打跨域名的电话吗?
<script>
$(function() {
$("#callAjax").click(function() {
var theName = $.trim($("#theName").val());
if(theName.length > 0)
{
$.ajax({
type: "GET",
url: "http://www.bcbustransit.uni.me/callajax.php",
data: ({name: theName}),
crossDomain: true,
cache: false,
dataType: "text",
success: onSuccess
});
}
});
$("#resultLog").ajaxError(function(event, request, settings, exception) {
$("#resultLog").html("Error Calling: " + settings.url + "<br />HTTP Code: " + request.status);
});
function onSuccess(data)
{
$("#resultLog").html("Result: " + data);
}
});
</script>。
<?php
$con=mysqli_connect("freehosting","xyz","xyz","xyz","3306");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_select_db($con,"u197344625_cfv");
$result = mysqli_query($con,"SELECT * FROM cfv_businfofull WHERE busnumber = 1 ");
echo "<table border='1'>
<tr>
<th>Bus Number</th>
<th>StopNames</th>
<th>Time</th>
<th>Day Of Week </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['BusNumber'] . "</td>";
echo "<td>" . $row['StopNames'] . "</td>";
echo "<td>" . $row['Timings'] . "</td>";
echo "<td>" . $row['DayOfWeek'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>发布于 2014-03-09 04:24:14
你应该看看CORS。
在您的示例中,您只需在服务器端添加带有响应的Access-Control-Allow-Origin: *头。注意,您应该只使用受信任的域而不是*。
https://stackoverflow.com/questions/22278348
复制相似问题