我正在使用jQuery ajax来调用我已验证正在工作并提交到sql数据库的coldfusion查询。我收到此JSON错误:SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 5 of the JSON data
所有内容仍然正确地发布到数据库,但错误导致它无法进入窗口重新加载的成功路由。有没有人注意到我在这里做错了什么?
JS
$('#employeeLoggedOut').on('submit', function (e) {
e.preventDefault();
//alert($(this).serialize());
console.log($(this).serialize());
$.ajax({
// the location of the CFC to run
url: "proxy/Completed.cfm",
// send a GET HTTP operation
type: "post",
// tell jQuery we're getting JSON back
dataType: "json",
// send the data to the CFC
data: $('#employeeLoggedOut').serialize(),
// this gets the data returned on success
success: function (data) {
console.log(data);
window.location.reload();
},
// this runs if an error
error: function (xhr, textStatus, errorThrown) {
// show error
console.log(errorThrown);
}
});
});
});
CF
<cfset session.dealerwork.completedname = form.CompletedName >
<cfoutput>#SerializeJSON(session.dealerwork.completedname)#</Cfoutput>
<cfset session.dealerwork.idtocomplete = form.selectedRow >
<cfoutput>#SerializeJSON(session.dealerwork.idtocomplete)#</Cfoutput>
<cfquery name="completeBatch">
UPDATE dbo.Dealer_Track_Work
SET Date_Complete = getDate(),
Closed_by = <cfqueryparam value="#session.dealerwork.completedname#" cfsqltype="cf_sql_varchar">
WHERE id = <cfqueryparam value="#session.dealerwork.idtocomplete#" cfsqltype="cf_sql_integer">
</cfquery>
答案 0 :(得分:2)
您只能发送一个json输出,而您正在发送几个。
尝试发送:
<cfoutput>#SerializeJSON(session.dealerwork)#</cfoutput>
然后作为回应,您应该有2个对象属性completedname
和idtocomplete
。
似乎您应该在发送肯定响应之前首先确认更新查询