Javascript 解析restfulapi:curl到ajax
我正在使用Parse RESTful API。我想在使用Ajax发送GET请求时附加一些约束,但他们网站上的示例都是用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
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我试过你的建议,效果不错。谢谢