fred basset
fred basset

Reputation: 10082

jQuery .ajax call not returning data

I'm trying to update my HTML UI with data returned from a server running on an embedded system (means I have full control over what is returned). The data callback in the .ajax function never seems to be called however, why would this be?

The jQuery code is


$(document).ready(function() {
    $('#pollGps').click(function() {
        alert('calling /pollgps.json'); 
        $.ajax({
            url: '/pollgps.json',
            dataType:'json',
            success: function( data ) {
                alert('success ' + JSON.stringify(data));
                $("#settingId").html(data.settingId);
                $("#settingValue").html(data.settingValue);
            }
            error: function(jqXHR, textStatus, errorThrown) {
                alert('Error polling GPS ' + textStatus);
            }
        });
    });
})

and the server response is

HTTP/1.0 200 OK
Content-Type: application/json

{
"settingId"="CFG-NAV2",
"settingValue"="0xdead"
}

Upvotes: 0

Views: 1214

Answers (1)

epascarello
epascarello

Reputation: 207511

This is not valid JSON

{
    "settingId"="CFG-NAV2",
    "settingValue"="0xdead"
}

The following is

{
    "settingId" : "CFG-NAV2",
    "settingValue" : "0xdead"
}

Get familiar with JSONLint.

Upvotes: 2

Related Questions