JQuery中的ajax怎么传参到后台

JQuery中的ajax怎么传参到后台


慕容森
浏览 590回答 1
1回答

慕斯709654

jquery中ajax只需配置相应的参数即可传参到后台页面。格式如下:$.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "get",//数据发送的方式(post 或者 get)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: "/admin/index",//要发送的后台地址&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: {val1:"1",val2:"2"},//要发送的数据(参数)格式为{'val1':"1","val2":"2"}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType: "json",//后台处理后返回的数据格式&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function (data) {//ajax请求成功后触发的方法&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert('请求成功');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error: function (msg) {//ajax请求失败后触发的方法&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(msg);//弹出错误信息&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });});后台接收数据(参数)<?phpval1 = $_GET['val1'];//1val2 = $_GET['val2'];//2?>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery