n****2 发帖数: 307 | 1 请求的url格式:
POST 方法 http:www.xxx.com/aaa/bbb/ccc?xxx={$xxx}&yyy={$yyy}&zzz={$zzz}
URI = http:www.xyz.com/aaa/bbb/ccc
data = {
xxx: $xxx,
yyy: $yyy,
zzz: $zzz,
}
好像 JSON.stringify(data)能得到这样的string:
{ xxx={$xxx}&yyy={$yyy}&zzz={$zzz} }
最后构造请求的时候要不要自己拼那个url:
URI+"?"+JSON.stringify(data)去除"{"和"}"
还是用URI创建请求后,把JSON.stringify(data)付给请求的data就完了?
多谢! | d****i 发帖数: 4809 | 2 Your method should be GET rather than POST based on your description. So it
should be
GET /aaa/bbb/ccc?xxx={$xxx}&yyy={$yyy}&zzz={$zzz}
If you're using JS to send the data, I recommend to use jQuery since it
automatically converts your data to JSON when you specify the 'dataType' as
JSON. Then you don't have to use raw JS to convert.
JSON.stringify(data) will convert data to JSON string:
{ "xxx":{$xxx}, "yyy":{$yyy}, "zzz": {$zzz} }
So this probably isn't what you wanted. Also, the {} and $ around xxx is
superfluous.
【在 n****2 的大作中提到】 : 请求的url格式: : POST 方法 http:www.xxx.com/aaa/bbb/ccc?xxx={$xxx}&yyy={$yyy}&zzz={$zzz} : URI = http:www.xyz.com/aaa/bbb/ccc : data = { : xxx: $xxx, : yyy: $yyy, : zzz: $zzz, : } : 好像 JSON.stringify(data)能得到这样的string: : { xxx={$xxx}&yyy={$yyy}&zzz={$zzz} }
| n****2 发帖数: 307 | |
|