Javascript Ajax到php文件错误
我从Ajax调用Javascript Ajax到php文件错误,javascript,php,jquery,json,ajax,Javascript,Php,Jquery,Json,Ajax,我从Ajax调用xhr参数中得到一条非常通用的错误消息 readyState 0 responseText "" statusText "error" 其余的都是function()或function(e)或function(e,t) 我知道问题不可能是基于域的错误,因为我正在调用同一台服务器,而且它是本地的 以下是脚本: $(function(){ $.ajaxSetup({ timeout: 100000 //Time in millisec
xhr
参数中得到一条非常通用的错误消息
readyState 0
responseText ""
statusText "error"
其余的都是function()
或function(e)
或function(e,t)
我知道问题不可能是基于域的错误,因为我正在调用同一台服务器,而且它是本地的
以下是脚本:
$(function(){
$.ajaxSetup({
timeout: 100000 //Time in milliseconds
});
loadTest();
});
function loadTest(){
//var postValues=null;
$.post("pieTest.Json.php")
.done(function(data){
console.log("pi: "+data.pie+" Time: "+data.sequentialTime)
})
.fail(function(xhr,textStatus,errorThrown){
console.log(xhr);
})
}
下面是它调用的文件(称为pieTest.Json.php)中的文本:
22751似乎是我可以传递的没有上述错误的最高参数。为什么设置时间限制(200)?它将在代码返回之前停止执行服务器的默认值为30,因此我将其设置为200以确保服务器没有计时。
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/php/init.php");
$result = array();
set_time_limit ( 200 );
try {
$startT = time();
$result['pie'] = pie(100000);
$endT = time();
$result['sequentialTime']=$endT-$startT;
$result['seqStart']=$startT;
$result['endTime']=$endT;
}catch(DisplayableException $e){
$result['status'] = "fail";
$result['errorMessage'] = $e->getMessage();
}catch (exception $e){
$result['status'] = "fail";
$result['errorMessage'] =$e->getMessage();
inspect($e);
}
header('Content-Type: application/json');
echo json_encode($result);
function pie ($n)
{
if ($n==1)
return 4*1;
else
return ( 4*(pow(-1,$n+1)*(1/(2*$n-1))) + pie($n-1) );
}