问题描述
假设您有以下POST网址,
Lets say you have following urls for POST,
url="http://www.example.com/processor?param1=val1¶m=val2"
url2="http://www.example.com/processor"
假设您正在使用Jquery发送POST请求.
Say you are sending POST request using Jquery.
$.post(url,{},function(){});
这与
$.post(url2,{"param1":"val1","param2":"val2"},function(){});
你也可以做类似的事情吗,
Can you also do something like,
$.post(url1,{"param1":"val1","param2":"val2"},function(){});
在POST URL中使用参数(例如上方的url(不是url2))是一种好习惯吗?
Is is a good practice to use parameters in POST URL (like url above (not url2))?
推荐答案
区别在于在后端处理变量.
The difference is in handling the variables on the backend.
在url1中,参数作为GET变量发送,在url2中,与post()结合使用,参数作为POST变量发送.
In url1, the parameters are sent as GET variables, and in url2, combined with the post(), the parameters are sent as POST variables.
我使用了组合,因此您可以互换使用它们.一般规则是使用GET发送教学"类型的数据,并发送POST发送用户数据"以进行数据操作.例如
I use a combination, so you can use them interchangably. The general rule is to use GET to send 'instructional' type data, and to send POST to send 'user data' for data manipulation. For example
url="http://www.example.com/look_for_product?product_type=monitors&supplier=dell"
比较
$.post('http://www.example.com/place_order;,{"product_type":"monitor","supplier":"dell"}.
您也可以使用组合
$.post('http://www.example.com/place_order?product_type=monitors&supplier=dell;,{"colour":"black","quantity":"3"}.
这篇关于POST网址中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!