Skip to content Skip to sidebar Skip to footer

Simple POST Request With Ajax

I'm trying to do a simple post request to use the OGRE web app to convert JSON files to shapefiles. I wrote this code, but the file doesn't download like it supposed to be, [edit]

Solution 1:

there is no such property json for jquery ajax, to add the json as post-data do like this:

function sendPost() {
    $.ajax({
        type: "POST",
        url: 'http://ogre.adc4gis.com/',
        data: {json:JSON.stringify(data)  },
        success: success
    });
}

in your success handler you will have the response in result dont expect your browser to download something as stated in Quentins Answer.


Solution 2:

but the file doesn't download like it supposed to be.

The file isn't supposed to download.

You have made an Ajax request. The response to it will be handled by JavaScript. It will only be handled by JavaScript. The JavaScript you wrote to handle it just calls alert (and nothing else).

If you want the browser to handle it in the same way as if you had submitted a regular form (without JavaScript) then you should submit a regular form. The whole point of Ajax is to handle the response in a custom way.


Post a Comment for "Simple POST Request With Ajax"