Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2013
    Thanked 0 Times in 0 Posts

    JSON request submitted using form and jQuery

    I am trying to submit a JSON request to a Tranzact api using jQuery and AJAX. Right now it keeps coming up as unsuccessful. I cant figure out how to print the results to see if it matches this provided:
    {"Authentication":{"UserName":"test","Password":"test"},”Site”:”FortLee”,"LeadDatetime":"2013-01-16T17:55:49.5229485-05:00","SourceTransactionId":"1234567","FirstName":"Test",”MiddleName”:”Joe”,”LastName":"Test",”Lead Router”:”walmart”,"EmailAddress":"test@test.com", “PhoneNumber”:”201333999”,”AltPhoneNumber”:”2012423231”,"AgentCallBackRequested":”Yes”,"PilotFlagInd icator":"Y",” WalmartDiscountCode “:”23456789”,"CampaignAttributes":null,” PreferredTimeToContact”:null,” PreferredMethodOfContact”:null,”LeadSource”:”UPS”,”MarketerId”:”UPS”,”Address”:{ ”AddressLine1”:”123 Main St”,”AddressLine2”:null,"City”:”Stafford”,”State”:”TX”,”zip”:”77477”}}

    Supposed to get

    I get:
    { "Success": "false", "LeadId": "0", "errorText": "Unexpected error occured" }

    Any help is appreciated.

    <title>Test JSON form</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
        $.post($(this).attr("action"), $(this).serialize(), function(jsonData){
        }, "json");
    form {
        line-height: 2em;
    p {
        margin: 5px 0;
    h2 {
        margin: 10px 0;
        font-size: 1.2em;
        font-weight: bold
    #result {
        margin: 10px;
        background: #eee;
        padding: 10px;
        height: 40px;
        overflow: auto;
        <form action="http://qa.oms.autoinsurance.com/api/lead/post" method="post" id="myForm" >
            Username:<input type="text" name="UserName" maxlength="36" size="12"/> <br/>
            password:<input type="text" name="Password" maxlength="36" size="12"/> <br/>
            LeadDatetime:<input type="text" name="LeadDatetime" maxlength="36" size="12"/> <br/>
            FirstName:<input type="text" name="FirstName" maxlength="36" size="12"/> <br/>
            LastName:<input type="text" name="LastName" maxlength="36" size="12"/> <br/>
            State:<input type="text" name="State" maxlength="36" size="12"/> <br/>
            Zip:<input type="text" name="Zip" maxlength="36" size="12"/> <br/>
            LeadRouter:<input type="text" name="LeadRouter" maxlength="36" size="12" value="‘walmart’"/> <br/>
            PhoneNumber:<input type="text" name="PhoneNumber" maxlength="36" size="12"/> <br/>
            LeadSource:<input type="text" name="LeadSource" maxlength="36" size="12" value="'UPS’"/> <br/>
            MarketerId:<input type="text" name="MarketerId" maxlength="36" size="12" value="'UPS’"/> <br/>
            <p><input type="submit" id="submitButton" /></p>
    <pre id="result">

  2. #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Thanked 257 Times in 253 Posts
    First, since you're doing ajax to submit the form, you should add return false at the end of the submit event handler to prevent the form from being submitted.

    If the error persists, then check the post data you are passing to the ajax request. Make sure the name and values are what the api expects. I noticed that the LeadSource and MarketerId fields have value="'UPS'". LeadRouter field has single quotes in the value too. Are you sure you need the single quotes there?
    Last edited by glenngv; 06-13-2014 at 08:35 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts