0

This is the top part the JSON String, I can supply the full string, but it is rather large.

{
    "InspectionResultAggregate": {
        "ValuationAggregate": {
            "MainStreetValuation": {
                "ValuationIdentifier": {
                    "RecordId": 2393438,
                    "PolicyNumber": "1143822",
                    "VersionId": 7005058
                },
                "RecordType": "INS",
                "DataSource": "FIT",
                "PropertyAddress": {
                    "Address1": "9-11 EDGEWOOD AVENUE ",
                    "Address2": " ",
                    "City": "ATTLEBORO",
                    "StateOrProvince": "MA",
                    "ZipOrPostalCode": "02703"
                },
                "OwnerUser": "UnknownUser",
                "AssignedByUser": "PrimeVal_FIT",
                "CreateDate": "2014-04-07T12:04:26.22",
                "CreateUser": "PrimeVal_FIT",
                "UpdateDate": "2014-04-18T12:27:00.4390372-07:00",
                "UpdateStatusDate": "2014-04-07T12:04:25.433",
                "UpdateUser": "PrimeVal_FIT",
                "InsuredCustomer": {
                    "FullName": "CAROL AND TREVOR CLARKE ",
                    "SecondFullName": " ",
                    "MailingAddressSameAsPropertyAddress": true,
                    "MailingAddress": {
                        "Address1": "",
                        "Address2": "",
                        "City": ""
                    }
                }

This is the Code: No matter what I try, I can not assign the policynumber to var p.

// CALCULATE VALUE
$('#calculate').click(function () {
    $('#general_message').text('Calculating...').fadeIn(1);
    dataString = $('form').serialize();
    $.ajax({
        type: "POST",
        url: "ajax_submit_soap_request.php",
        data: dataString,
        datatype: 'json',
        success: function (data) {
            alert(data);
            $('#general_message').text('Calculation Finished!').fadeOut(3000);
            var p = data.InspectionResultAggregate.ValuationAggregate.MainStreetValuation.ValuationIdentifier.PolicyNumber;
            $('#policy').text(p);
        }
    });
    return false;
})
4
  • 2
    A sample of the JSON string is fine, but try to make sure it's valid. As is, it's missing 4 }. But, have you tried adding an error handler to the $.ajax() request and inspected the errorThrown? Commented Apr 18, 2014 at 20:18
  • 1
    Any errors in the console? Have you tried logging data to the console and seeing if it looks like you expect it to? Commented Apr 18, 2014 at 20:20
  • Fix your JSON Structure. you can use this online tool very helpfull. Commented Apr 18, 2014 at 20:27
  • The first sentence reads that the JSON being supplied is the top part of the object, not the full object. It would be helpful if you posted the entire object, or even better, use an online tool to verify it's a legitimate JSON object. Commented Apr 18, 2014 at 20:33

1 Answer 1

2

You tried to set the dat type with datatype, when it should be dataType

dataType: 'json',
Sign up to request clarification or add additional context in comments.

4 Comments

but the default value is "educated guess" which will usually esult in JSON anyways for a json string
@RuneFS Though, the educated guess is based on the responding Content-Type, which may not be application/json or similar for auto-parsing.
@JonathanLonowski yes yes im just sying it's not evident from the context that the dataType would cause ny problem (though specifying it like this is of course without meaning)
Musa, thank you I can't tell you how long I looked at the code and did not see the typo! Thanks everyone else for the input.

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.