Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解析restfulapi:curl到ajax_Javascript_Ajax_Parse Platform - Fatal编程技术网

Javascript 解析restfulapi:curl到ajax

Javascript 解析restfulapi:curl到ajax,javascript,ajax,parse-platform,Javascript,Ajax,Parse Platform,我正在使用Parse RESTful API。我想在使用Ajax发送GET请求时附加一些约束,但他们网站上的示例都是用curl编写的,其中一个示例是: curl -X GET \ -H "X-Parse-Application-Id: IWphomqAahPnmElGbu8k8NlXvyCCf3YItYZRD03X" \ -H "X-Parse-REST-API-Key: 2RodxwlOfr1U124ZFu6yBN8bJHvDWoVc60srbOW9" \ -G \ --dat

我正在使用Parse RESTful API。我想在使用Ajax发送GET请求时附加一些约束,但他们网站上的示例都是用
curl
编写的,其中一个示例是:

curl -X GET \
  -H "X-Parse-Application-Id: IWphomqAahPnmElGbu8k8NlXvyCCf3YItYZRD03X" \
  -H "X-Parse-REST-API-Key: 2RodxwlOfr1U124ZFu6yBN8bJHvDWoVc60srbOW9" \
  -G \
  --data-urlencode 'where={"playerName":"Sean Plott","cheatMode":false}' \
  https://api.parse.com/1/classes/GameScore

我不知道Ajax中的--data-urlencode的等价物。我已经尝试将
--data urlencode
之后的约束放在Ajax调用的
data
中,但它不起作用。

这意味着您需要对字符串进行url编码。试试看,用javascript就行了。它的作用如下:而不是调用
http://restapi.url?param=where={“playerName”:“Sean plot”,“cheatMode”:false}
(不正确)它发送:
http://restapi.url?param=where%3D%7B%22playerName%22%3A%22Sean%20Plott%22%2C%22cheatMode%22%3Afalse%7D
其中:JSON.stringify({…})
@skobaljic我试过你的建议,效果不错。谢谢