Can someone explain to me why I get the below error by executing the following code?
有人可以向我解释为什么我通过执行以下代码得到以下错误?
SyntaxError : JSON.parse : unexpected end of data at line 1 column 1 of the JSON data"
SyntaxError:JSON.parse:JSON数据第1行第1列的意外数据结尾“
After thousands of trials, I realized that if I replace the value 0
from StatutForm
with 2
or anything else, the error disappears. FormData
does not accept the value 0
?
经过数千次试验,我意识到如果我用2或其他任何东西替换StatutForm中的值0,则错误消失。 FormData不接受值0?
Thank you for your help.
谢谢您的帮助。
The code :
代码 :
$(document).on('click', '.button1, .button2', function() {
var Form_id = $(this).attr('data-id');
var formData = new FormData();
formData.append("IDForm", $('#IDForm' + Form_id).val());
formData.append("FirstnameForm", $('#FirstnameForm' + Form_id).val());
formData.append("NameForm", $('#NameForm' + Form_id).val());
formData.append("BirthForm", $('#BirthForm' + Form_id).val());
formData.append("EmailForm", $('#EmailForm' + Form_id).val());
formData.append("SchoolForm", $('#SchoolForm' + Form_id).val());
formData.append("DateFromForm", $('#DateFromForm' + Form_id).val());
formData.append("DateToForm", $('#DateToForm' + Form_id).val());
formData.append("DaysForm", $('#DaysForm' + Form_id).val());
formData.append("TodayForm", $('#TodayForm' + Form_id).val());
if (!$(this).hasClass('button1')) {
formData.append("StatutForm", "1");
}
else {
var texte_Form = $('#ecrire_' + Form_id).val();
var mail_Form = new Blob([texte_Form], { type: "text/xml"});
formData.append("mail_Form", texte_Form);
formData.append("StatutForm", "0");
}
$.ajax({
type: 'POST',
url: 'file.php',
dataType: "json",
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (form) {
alert("Right !.");
},
error: function(){
alert("Error !");
}
});
});
1 个解决方案
#1
You receive an error when parsing data received from the server.
解析从服务器收到的数据时收到错误。
dataType: "json"
dataType – The type of data that you're expecting back from the server.
dataType - 您期望从服务器返回的数据类型。
json – Evaluates the response as JSON and returns a JavaScript object.
json - 将响应评估为JSON并返回JavaScript对象。
#1
You receive an error when parsing data received from the server.
解析从服务器收到的数据时收到错误。
dataType: "json"
dataType – The type of data that you're expecting back from the server.
dataType - 您期望从服务器返回的数据类型。
json – Evaluates the response as JSON and returns a JavaScript object.
json - 将响应评估为JSON并返回JavaScript对象。