0
我正在閱讀csv文件通過使用ajax調用加載我得到的結果在Mozilla中,但相同的鏈接,如果我在鉻中執行我得到一個錯誤「XMLHttpRequest無法加載文件:/// home/scriplogix7/Downloads/csv-text-file-uploader/data.csv。只有協議方案支持跨源請求:http,data,chrome-extension,https,chrome-extension-resource。所以我怎麼能在鉻中處理這個錯誤。通過使用jquery csv文件讀取
我的代碼是。
$(document).ready(function() {
// AJAX in the data file
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {
processData(data);
}
});
// Let's process the data from the data file
function processData(data) {
var table = $("<table />");
var rows = data.split(/\r\n|\n/);
for (var i = 1; i < rows.length - 1; i++) {
var row = $("<tr />");
var cells = rows[i].split(",");
for (var j = 0; j < rows.length; j++) {
var cell = $("<td />");
cell.html(cells[j]);
row.append(cell);
}
var usedNames = {};
$("select[name='company1'] > option").each(function() {
if (usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
$("select[name='company2'] > option").each(function() {
if (usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
$("select[name='company3'] > option").each(function() {
if (usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
$("#region").append("<option value =1> " + cells[0] + " </option>");
$("#state").append("<option value =1> " + cells[1] + "</option>");
$("#accname").append("<option value =1>" + cells[2] + "</option>");
table.append(row);
}
}
});
您可以搜索錯誤味精像[這裏](http://stackoverflow.com/search?q=XMLHttpRequest+cannot+負載+跨+原點+請求+是+僅支持+ + +爲+協議方案%3A + HTTP%2C +數據%2C +鉻擴展%2C +)。 – RRK