[Fixed]-Django/AJAX: Sending and receiving a response with POST

0👍

Here is the sequence that finally worked for me:

$.each (json.features, function (i, val)
    name.push(val.properties.name);
    zip.push(val.properties.zip);
});

name , zip and tags are my model columns. The rest is Django’s JSON. I should point out that I am using the GeoJSON serializer here.

Here is a chart I made to help me visualize the JSON pattern:

{"type": 
    "FeatureCollection", 

    "crs": {
        "type": "name",  
        "properties":  {
            "name": "EPSG:4326" 
        }}, 

    "features": [{
            "geometry": null, 
            "properties": {
                "zip": "19146", 
                "name": "Jamboree", 
                "tags": []}, 
                "type": "Feature"
            }, 

            {
            "geometry": null, 
            "properties": {
                "zip": "19146", 
                "name": "Party", 
                "tags": []}, 
                "type": "Feature"
            }]
}

Thanks to everyone for helping me learn this!

1👍

You’re iterating through the results value of the JSON, but as you can see from your sample output, there is no such value. You need to iterate through crs.features.

$.each (json.crs.features, function (i, val) {
    name.push(val.properties.name);
    zip.push(val.properties.zip);
}

0👍

Try adding:

dataType:"json",

to your $.ajax call. Does this fix it?

Leave a comment