0
當我們中止ajax請求時,我正在從PHP服務器上延遲ajax響應。 我正在爲服務器腳本使用codeigniter框架。來自服務器的延遲響應,同時中止jquery ajax
JavaScript代碼:
cblcurrentRequest = $.ajax({
url: baseurl + 'Login/getChannelBrand/' + brand_id,
type: 'post',
async: true,
cache: true,
data: '',
beforeSend: function() {
$('#tw').html("");
$('#fb').html("");
$('#inst').html("");
$('#yt').html("");
if (cblcurrentRequest != null) {
cblcurrentRequest.abort();
}
if (firsttwcurrentRequest != null) {
firsttwcurrentRequest.abort();
}
if (firstfbcurrentRequest != null) {
firstfbcurrentRequest.abort();
}
if (firstigcurrentRequest != null) {
firstigcurrentRequest.abort();
}
if (firstytcurrentRequest != null) {
firstytcurrentRequest.abort();
}
if (twcurrentRequest != null) {
twcurrentRequest.abort();
}
if (fbcurrentRequest != null) {
fbcurrentRequest.abort();
}
if (igcurrentRequest != null) {
igcurrentRequest.abort();
}
if (ytcurrentRequest != null) {
ytcurrentRequest.abort();
}
},
success: function (result) {
var channelBrandList = JSON.parse(result);
facebookBrandName = channelBrandList['FacebookChannel'];
twitterBrandName = channelBrandList['TwitterChannel'];
youtubeBrandName = channelBrandList['YoutubeChannel'];
instagramBrandName = channelBrandList['InstagramChannel'];
YelpBrandName = channelBrandList['YelpChannel'];
console.log(facebookBrandName);
console.log(twitterBrandName);
console.log(youtubeBrandName);
console.log(instagramBrandName);
console.log(yelpBrandName);
}
})
登錄Controllor
function getChannelBrand($brandID) {
$channelBrandList = $this->Model_brand->getChannelBrandList($brandID);
$channelbrand_array = array('BrandId' => $channelBrandList[0]->BrandId,
'BrandName' => $channelBrandList[0]->BrandName,
'FacebookChannel' => $channelBrandList[0]->FacebookChannel,
'TwitterChannel' => $channelBrandList[0]->TwitterChannel,
'YoutubeChannel' => $channelBrandList[0]->YoutubeChannel,
'InstagramChannel' => $channelBrandList[0]->InstagramChannel,
'YelpChannel' => $channelBrandList[0]->YelpChannel
);
echo(json_encode($channelbrand_array));
}
型號代碼:
function getChannelBrandList($brandID) {
$query = $this->db->query('SELECT * FROM brands where BrandId='.$brandID);
if (count($query->result()) > 0) {
return $query->result();
} else {
return $query = "";
}
}
JSON響應:
{
"BrandId":"26",
"BrandName":"jeep",
"FacebookChannel":"jeep",
"TwitterChannel":"jeep",
"YoutubeChannel":"thejeepchannel",
"InstagramChannel":"jeep",
"YelpChannel":null
}
控制檯日誌:
請建議,如果需要對框架級別或任何其他任何配置。
感謝, Sameek
考慮兩件事情會更快的查詢1.使用查詢like'select COL1,col2'不'選擇*',2,使用數組返回的結果,而不是目的。數組比對象快。 問題:您可以顯示請求的時間嗎? –
沒有ajax中止它需要-1076ms。與ajax中止它需要:22925ms,還包括顯示時間框架的屏幕截圖。 –
你的'pconnect'設置是什麼?在database.php –