使用Ajax进行简单的POST请求

编程入门 行业动态 更新时间:2024-10-24 16:31:50
本文介绍了使用Ajax进行简单的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试做一个简单的发布请求,以使用 OGRE网络应用将JSON文件转换为shapefile .

I'm trying to do a simple post request to use the OGRE web app to convert JSON files to shapefiles.

我编写了这段代码,但是文件没有按原样下载,[edit],甚至都没有上传json.

I wrote this code, but the file doesn't download like it supposed to be, [edit] and it doesn't even upload the json.

网站将其指定为输入请求参数:

The website specifies this as the input request params:

ogre.adc4gis/convertJson with one of the following params: json - text of the GeoJSON file jsonUrl - the URL for a remote GeoJSON file outputName (optional) - the name for the resulting zip file skipFailures (optional) - skip failures

我在做什么错了?

<html> <head> <script src="code.jquery/jquery-2.2.0.min.js" type="text/javascript"></script> </head> <body> <input type="button" value="Send Post" onclick="sendPost()"> <script> var data = { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": { "prop0": "value0" } }] }; function sendPost() { $.ajax({ type: "POST", url: 'ogre.adc4gis/convertJson', json: data, success: success }); } function success(result) { alert('Process achieved!'); } </script> </body> </html>

我收到此错误:

Object {error: true, msg: "No json provided"}

出什么问题了?

推荐答案

jquery ajax没有这样的属性json, 将json添加为后数据的方法如下:

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: 'ogre.adc4gis/', data: {json:JSON.stringify(data) }, success: success }); }

在成功处理程序中,您将在result中得到响应 不要期望您的浏览器会下载Quentins答案中所述的内容.

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

更多推荐

使用Ajax进行简单的POST请求

本文发布于:2023-11-24 19:51:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   Ajax   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!