某些原因,我可以在Chrome中返回數據從POST
罰款。阿賈克斯數據是不一樣的鉻與火狐
{"email":"[email protected]","customer_id":20413,"credit_amount":50.0,"currency_symbol":"$"}
但是當同樣的POST
是在火狐完成我得到以下錯誤:
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
不知何故,data
沒有被處理的相同使用Chrome時,返回的數據看起來像這樣我不知道爲什麼。
這裏是產生Ajax請求
function getCustomerAndCredit() {
console.log("getCustomerAndCredit");
$(function() {
$("form[action='" + shopAddress + "/account/login']").submit(function(event){
console.log("this is past the submit event in Firefox");
var custEmail = $("form[action='" + shopAddress + "/account/login'] input[type=email]").val();
var pass = $("form[action='" + shopAddress + "/account/login'] input[type=password]").val();
sessionStorage.setItem('custEmail', custEmail);
sessionStorage.setItem('pass', pass);
sessionStorage.setItem('loggedIn', true);
debugger;
$.ajax({
url: "/apps/proxy/return_customer",
data: {email: custEmail},
type: "POST",
dataType: "js",
complete: function(data) {
debugger;
if(noCustomerInDB(data)){
if(data.responseJSON == undefined){
sessionStorage.setItem('customer_id', JSON.parse(data.responseText).customer_id);
sessionStorage.setItem('creditAmount', JSON.parse(data.responseText).credit_amount);
sessionStorage.setItem('currency', JSON.parse(data.responseText).currency_symbol);
}
else {
sessionStorage.setItem('customer_id', data.responseJSON.customer_id);
sessionStorage.setItem('creditAmount', data.responseJSON.credit_amount);
sessionStorage.setItem('currency', data.responseJSON.currency_symbol);
}
}
// console.log("What is the credit_amount here in getCustomerAndCredit " + sessionStorage.getItem('creditAmount'));
},
});
});
});
}
代碼,然後這是那裏的data
是怎麼回事:
function noCustomerInDB(data){
console.log("this is the todd variable " + data);
console.log("stringify data " + JSON.stringify(data));
console.log("what about just data?? " + JSON.parse(data));
console.log("this is the response down here in the no customer function" + data.responseText);
if(data.responseText == ""){
return false;
}
else{
if (JSON.parse(data.responseText).customer_id == "no_customer"){
sessionStorage.setItem('creditAmount', "null");
return false;
}
else{
return true;
}
}
}
我做了一些更多的挖掘,現在它看上去就像個ajax
ISN不會被FireFox調用。因爲從POST
返回的數據是這樣的:
{"readyState":0,"status":0,"statusText":"error"}
'數據類型:js'無效。我注意到FF對數據類型更嚴格一些,因爲Chrome做出了更多的假設。更改爲JSON – Leeish
...也不是你應該使用字符串類型JSON.parse?但似乎你正在返回一個JSON? – 82Tuskers
我的上帝我只注意到你在客戶端會話中存儲了一個密碼以及一個「loggedIn」標誌。只是...不這樣做。客戶端上的任何內容都可以由用戶修改,任何惡意軟件都可以檢查客戶端上的數據。 – Leeish