jquery - Ajax call SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data -
i trying make ajax call using jquery , setting session variables using coldfusion 10. error receiving:
syntaxerror: json.parse: unexpected end of data @ line 1 column 1 of json data
am overlooking something?
$('#tooltables_processing_1').on('click', function () { $.ajax({ // location of cfc run url: "redirects/selectedrows.cfm", // send http operation type: "post", // tell jquery we're getting json datatype: "json", // send data cfc data: $('#form').serialize(), // gets data returned on success success: function (data) { console.log(data); window.location = 'forms/exitinterviewpdf.cfm'; }, // runs if error error: function (xhr, textstatus, errorthrown) { // show error console.log(errorthrown); } }); });
if take out datatype: json
empty string.
selectedrows.cfm
<cfset session.exitinterview.selected.selectedrowname = form.selectedrowname > <cfset session.exitinterview.selected.selectedrowtodaydate = form.selectedrowtodaydate > <cfset session.exitinterview.selected.selectedrowtitle = form.selectedrowtitle > <cfset session.exitinterview.selected.selectedrowdepartment = form.selectedrowdepartment > <cfset session.exitinterview.selected.selectedrowhiredate = form.selectedrowhiredate > <cfset session.exitinterview.selected.selectedrowterminationdate = form.selectedrowterminationdate > <cfset session.exitinterview.selected.selectedrowreasonleaving = form.selectedrowreasonleaving > <cfset session.exitinterview.selected.selectedrowfeelpay = form.selectedrowfeelpay > <cfset session.exitinterview.selected.selectedrowprogresshere = form.selectedrowprogresshere > <cfset session.exitinterview.selected.selectedrowanotherjob = form.selectedrowanotherjob > <cfset session.exitinterview.selected.selectedrowcomparewith = form.selectedrowcomparewith > <cfset session.exitinterview.selected.selectedrowhighersalary = form.selectedrowhighersalary > <cfset session.exitinterview.selected.selectedrowpreventleaving = form.selectedrowpreventleaving > <cfset session.exitinterview.selected.selectedrowclearlyexplained = form.selectedrowclearlyexplained > <cfset session.exitinterview.selected.selectedrowbywhom = form.selectedrowbywhom > <cfset session.exitinterview.selected.selectedrowadequatetraining = form.selectedrowadequatetraining > <cfset session.exitinterview.selected.selectedrowworkperform = form.selectedrowworkperform > <cfset session.exitinterview.selected.selectedrowworkingcondition = form.selectedrowworkingcondition > <cfset session.exitinterview.selected.selectedrowsalary = form.selectedrowsalary > <cfset session.exitinterview.selected.selectedrowretirement = form.selectedrowretirement > <cfset session.exitinterview.selected.selectedrowhealthplan = form.selectedrowhealthplan > <cfset session.exitinterview.selected.selectedrowtuition = form.selectedrowtuition > <cfset session.exitinterview.selected.selectedrowunileave = form.selectedrowunileave > <cfset session.exitinterview.selected.selectedrowcoworkers = form.selectedrowcoworkers > <cfset session.exitinterview.selected.selectedrowsupervisionreceived = form.selectedrowsupervisionreceived > <cfset session.exitinterview.selected.selectedrowneededhelp = form.selectedrowneededhelp > <cfset session.exitinterview.selected.selectedrowmanagerrespond = form.selectedrowmanagerrespond > <cfset session.exitinterview.selected.selectedrowsuggestionsbetterplace = form.selectedrowsuggestionsbetterplace > <cfset session.exitinterview.selected.selectedrowrealreasonforleaving = form.selectedrowrealreasonforleaving > <cfset session.exitinterview.selected.selectedrowcomments = form.selectedrowcomments > <cfoutput>#serializejson(session.exitinterview.selected)#</cfoutput>
what when debugging large data sets narrow down problem. please try sample codes
<!doctype html> <html> <head> <title>title of document</title> <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <form id="form" method="post" onsubmit="javascript:return(false)"> <input type="text" name="selectedrowname" id="selectedrowname" value="vlad" > <input type="submit" id="tooltables_processing_1" value="save" > </form> <script type="text/javascript"> $(function(){ $('#tooltables_processing_1').on('click', function () { $.ajax({ // location of cfc run url: "redirects/selectedrows.cfm", // send http operation type: "post", // tell jquery we're getting json datatype: "json", // send data cfc data: $('#form').serialize(), // gets data returned on success success: function (data) { console.log(data); //window.location = 'forms/exitinterviewpdf.cfm'; }, // runs if error error: function (xhr, textstatus, errorthrown) { // show error console.log(errorthrown); } }); }); });//doc ready </script> </body> </html>
selectedrows.cfm
<cfset session.exitinterview.selected.selectedrowname = form.selectedrowname > <!---<cfset session.exitinterview.selected.selectedrowtodaydate = form.selectedrowtodaydate > <cfset session.exitinterview.selected.selectedrowtitle = form.selectedrowtitle > <cfset session.exitinterview.selected.selectedrowdepartment = form.selectedrowdepartment > <cfset session.exitinterview.selected.selectedrowhiredate = form.selectedrowhiredate > <cfset session.exitinterview.selected.selectedrowterminationdate = form.selectedrowterminationdate > <cfset session.exitinterview.selected.selectedrowreasonleaving = form.selectedrowreasonleaving > <cfset session.exitinterview.selected.selectedrowfeelpay = form.selectedrowfeelpay > <cfset session.exitinterview.selected.selectedrowprogresshere = form.selectedrowprogresshere > <cfset session.exitinterview.selected.selectedrowanotherjob = form.selectedrowanotherjob > <cfset session.exitinterview.selected.selectedrowcomparewith = form.selectedrowcomparewith > <cfset session.exitinterview.selected.selectedrowhighersalary = form.selectedrowhighersalary > <cfset session.exitinterview.selected.selectedrowpreventleaving = form.selectedrowpreventleaving > <cfset session.exitinterview.selected.selectedrowclearlyexplained = form.selectedrowclearlyexplained > <cfset session.exitinterview.selected.selectedrowbywhom = form.selectedrowbywhom > <cfset session.exitinterview.selected.selectedrowadequatetraining = form.selectedrowadequatetraining > <cfset session.exitinterview.selected.selectedrowworkperform = form.selectedrowworkperform > <cfset session.exitinterview.selected.selectedrowworkingcondition = form.selectedrowworkingcondition > <cfset session.exitinterview.selected.selectedrowsalary = form.selectedrowsalary > <cfset session.exitinterview.selected.selectedrowretirement = form.selectedrowretirement > <cfset session.exitinterview.selected.selectedrowhealthplan = form.selectedrowhealthplan > <cfset session.exitinterview.selected.selectedrowtuition = form.selectedrowtuition > <cfset session.exitinterview.selected.selectedrowunileave = form.selectedrowunileave > <cfset session.exitinterview.selected.selectedrowcoworkers = form.selectedrowcoworkers > <cfset session.exitinterview.selected.selectedrowsupervisionreceived = form.selectedrowsupervisionreceived > <cfset session.exitinterview.selected.selectedrowneededhelp = form.selectedrowneededhelp > <cfset session.exitinterview.selected.selectedrowmanagerrespond = form.selectedrowmanagerrespond > <cfset session.exitinterview.selected.selectedrowsuggestionsbetterplace = form.selectedrowsuggestionsbetterplace > <cfset session.exitinterview.selected.selectedrowrealreasonforleaving = form.selectedrowrealreasonforleaving > <cfset session.exitinterview.selected.selectedrowcomments = form.selectedrowcomments >---> <cfsetting showdebugoutput="false"> <cfcontent reset="true" > <cfoutput>#serializejson(session.exitinterview.selected)#</cfoutput>
as others suggested can malformed json data , figured out code in application.cfc problem.
Comments
Post a Comment