0

I am using jQuery ajax to call a coldfusion query that I have verified is working and submitting to the sql database. I am receiving this JSON error though: SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 5 of the JSON data

Everything is still posting to the database correctly but the error is causing it to not go the successful route where the window reloads. Does anyone notice what I may be doing wrong here?

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>

1 Answer 1

3

You can only send one json output and you are sending several.

Try sending:

<cfoutput>#SerializeJSON(session.dealerwork)#</cfoutput> 

Then in response you should have 2 object properties completedname and idtocomplete.

Seems like you should be confirming the update query however first before sending a positive response

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.