本篇文章给大家分享的内容是3种ajax的传值方式详解 ,有着一定的参考价值,有需要的朋友可以参考一下
var data=JSON.stringify({‘name”:name,”sex”:sex});
$.ajax({
//ajax传值方式:1,url后面直接跟参数(get),2,headers(get):传值方式。此处传值的时候,需要设置服务端的Access-Control-Allow-Headers中设置对应的参数名,才
//可以在header中加入想要传值的名字。3,body:传值方式(对应post),也就是data:{中间是json字符串/json对象}
url: restApiServer+ 'user?name=' + name, 服务端取值:request.query.name
type: 'GET',
dataType:"json",
headers: {"Authorization": "Basic " + Authorization + ":" +password, "code": code, "startIndex":jtParams.jtStartIndex, "pageSize": jtParams.jtPageSize,"sorting": jtParams.jtSorting }, 服务端取值:request.header(“参数名”);
data: data,||data:JsonObject,|| data:JsonStr 服务端取值:request.body.参数名,
success: function(data) {
if(data.success == 1) {
if(data.data.length <h4>1,使用express()框架的时候:</h4><p>客户端:<br>1)url后面直接跟参数(get) 服务器端取值:request.query.参数名 ,其中name是参数名字<br>2)headers(get/post),此处传值的时候,需要在跨域访问的access-control-allow-headers中设置对应的参数名字 服务器端取值:request.header(‘参数名’);<br>3)body(post):也就是中间的data(中间是json字符串/json对象) 服务器端取值:request.body.参数名<br></p><h4>2,使用koa2()框架的时候</h4><p>1)url后面直接跟参数(get) 服务器端取值:ctx.request.query.参数名 ,其中name是参数名字<br>2)headers(get/post),此处传值的时候,不需要在跨域那里使用header进行注册。 服务器端取值:ctx.request.header.参数名;<br>3)body(Post):也就是中间的data(中间是Json字符串/Json对象) 服务器端取值:ctx.request.body.参数名</p><p><span style="font-size: 16px;">相关推荐:</span></p><p><a href="https://blog.csdn.net/yasha97/article/details/78245258" target="_self" style="font-size: 16px; text-decoration: underline;"><span style="font-size: 16px;">原生ajax传值</span></a></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/learn/7014" title="AJAX技术—无刷新获取数据相关课件"><img
src="https://img.php.cn/upload/webcode/000/000/164/6152aff85d347738.jpg" alt="AJAX技术—无刷新获取数据相关课件" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/learn/7014" title="AJAX技术—无刷新获取数据相关课件" class="overflowclass">AJAX技术—无刷新获取数据相关课件</a>
<p class="overflowclass">AJAX技术—无刷新获取数据相关课件</p>
</div>
<a rel="nofollow" href="/xiazai/learn/7014" title="AJAX技术—无刷新获取数据相关课件" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p><a href="https://bbs.csdn.net/topics/391890070" target="_self" style="font-size: 16px; text-decoration: underline;"><span style="font-size: 16px;">关于MVC传值方式的区别</span></a></p><p><a href="https://blog.csdn.net/miachen520/article/details/51971091" target="_self" style="font-size: 16px; text-decoration: underline;"><span style="font-size: 16px;">Ajax中的两种传参方式详解</span></a></p>










