iOS上的Ajax内部500错误 [英] ajax internal 500 error on iOS
本文介绍了iOS上的Ajax内部500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Ajax读取文本文件,但是在ios上不起作用:仅在iOS上的proDB.txt文件上出现错误500(内部服务器错误).
I am trying to read a text file using ajax, but it doesn't work on ios : I get an error 500 (Internal Server Error) on the proDB.txt file on iOS only.
var prodata=[];
ajaxreadfile();
function ajaxreadfile() {
return $.ajax({
url: "proDB.txt",
type: 'GET',
dataType: 'text',
headers: { "cache-control": "no-cache" },
success: function(data){
readfile(data);
},
async: false
});
}
function readfile(data){
var lines=data.split(/\n/);
var i;
prodata.push(0);
var fieldnames=lines[0].split(/\t/);
for (i = 1; i < lines.length-1; ++i) {
var fields=lines[i].split(/\t/);
prodata.push(i);
var j;
prodata[i]={};
prodata[i]['id']=i; //auto id, there is no more 'id' column in the DB file.
for (j = 0; j < fields.length; ++j) {
var str=fieldnames[j];
prodata[i][str]=fields[j];
}
}
prodata.sort(SortByName);
resetLists(prodata);
prodata.sort(SortById);
}
你能告诉我怎么了吗?
推荐答案
要解决此问题,我使用iOS的文件的完整路径是这样的:
To solve the problem, I use the full path to the file for iOS like this :
var request = $.ajax({
url: dbUrl(),
type: 'get',
dataType: 'text',
success: successCallback
});
function dbUrl(){
if(isIOS()){
return "http://www.mysite.com/proDB.txt";
}else{
return "proDB.txt";
}
}
function isIOS(){
return (
(navigator.userAgent.indexOf("iPhone") != -1) ||
(navigator.userAgent.indexOf("iPod") != -1) ||
(navigator.userAgent.indexOf("iPad") != -1)
);
}
这篇关于iOS上的Ajax内部500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文