猿问
下载APP

请问描述一次完整的Ajax请求过程?

描述一次完整的Ajax请求过程


慕姐4208626
浏览 131回答 3
3回答

BIG阳

AJAX运行过程中5种状态:0 - (未初始化)还没有调用send()方法,1 - (载入)已调用send()方法,正在发送请求,2 - (载入完成)send()方法执行完成,3 - (交互)正在解析响应内容,4 - (完成)响应内容解析完成,可以在客户端调用了。$.post(url,params,function(data){},"json");Jquery发送的post请求 &nbsp; &nbsp;参数1:请求路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;一般在页面中,发送数据到controller层参数2:发送过去的参数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 获取到页面中的一些参数参数3:回调函数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请求成功,在controller层中对应的处理方法上面返回的数据参数4:请求和返回的数据类型 &nbsp; &nbsp; &nbsp; &nbsp; 可以是json这个是jquery包装的post请求,原始的ajax请求比较麻烦,我一般用的都是jquery封装的ajax请求这个方法,一定要注意最后的一个参数<script type="text/javascript">/*点击修改按钮,让市场价格,售价,库存,购买显示亮起来,可以输入数字 &nbsp;*/function updateSku(skuId) {$("#m" + skuId).attr("disabled", false);$("#p" + skuId).attr("disabled", false);$("#i" + skuId).attr("disabled", false);$("#l" + skuId).attr("disabled", false);/*获取修改后的,sku中的数据 &nbsp;*/function addSku(skuId)&nbsp;var m = $("#m" + skuId).attr("disabled", true).val();var p = $("#p" + skuId).attr("disabled", true).val();var i = $("#i" + skuId).attr("disabled", true).val();var l = $("#l" + skuId).attr("disabled", true).val();//保存var url = "/product/updateSku.do";var params = {"marketPrice" : m,"skuPrice" : p,"stockInventory" : i,"skuUpperLimit" :l,"id" : skuId };$.post(url,params,function(data){alert(data.message);<td align="center"><input type="text" id="m${sku.id}" name="marketPrice" value="${sku.marketPrice}"disabled="disabled" size="10" />// 库存中的保存 @RequestMapping("/product/updateSku.do") public voidupdateSku(Sku sku, Model model, HttpServletResponse response) { // 修改skuService.updateSkuByKey(sku); JSONObject jo = new JSONObject();jo.put("message", "保存成功!"); // 将ajax请求,返回一个成功的信息ResponseUtils.sendJson(response, jo.toString()); }

慕田峪4524236

$.post(url,params,function(data){},"json");Jquery发送的post请求 &nbsp; &nbsp;参数1:请求路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;一般在页面中,发送数据到controller层参数2:发送过去的参数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 获取到页面中的一些参数参数3:回调函数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请求成功,在controller层中对应的处理方法上面返回的数据参数4:请求和返回的数据类型 &nbsp; &nbsp; &nbsp; &nbsp; 可以是json这个是jquery包装的post请求,原始的ajax请求比较麻烦,我一般用的都是jquery封装的ajax请求这个方法,一定要注意最后的一个参数<script type="text/javascript">/*点击修改按钮,让市场价格,售价,库存,购买显示亮起来,可以输入数字 &nbsp;*/function updateSku(skuId) {$("#m" + skuId).attr("disabled", false);$("#p" + skuId).attr("disabled", false);$("#i" + skuId).attr("disabled", false);$("#l" + skuId).attr("disabled", false);}/*获取修改后的,sku中的数据 &nbsp;*/function addSku(skuId) {var m = $("#m" + skuId).attr("disabled", true).val();var p = $("#p" + skuId).attr("disabled", true).val();var i = $("#i" + skuId).attr("disabled", true).val();var l = $("#l" + skuId).attr("disabled", true).val();//保存var url = "/product/updateSku.do";var params = {"marketPrice" : m,"skuPrice" : p,"stockInventory" : i,"skuUpperLimit" : l,"id" : skuId };$.post(url,params,function(data){alert(data.message);},"json");}</script>-------------------------------------------------------------------------------<td align="center"><input type="text" id="m${sku.id}" name="marketPrice" value="${sku.marketPrice}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="p${sku.id}" name="skuPrice" value="${sku.skuPrice}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="i${sku.id}" name="stockInventory" value="${sku.stockInventory}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="l${sku.id}" name="skuUpperLimit" value="${sku.skuUpperLimit}"disabled="disabled" size="10" /></td>-----------------------------------------------------------------------------------------------------------// 库存中的保存 @RequestMapping("/product/updateSku.do") public void updateSku(Sku sku, Model model, HttpServletResponse response) { // 修改 skuService.updateSkuByKey(sku); JSONObject jo = new JSONObject(); jo.put("message", "保存成功!"); // 将ajax请求,返回一个成功的信息 ResponseUtils.sendJson(response, jo.toString()); }

哔哔one

完整的请求过程如下$.post(url,params,function(data){},"json");Jquery发送的post请求 &nbsp; &nbsp;参数1:请求路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;一般在页面中,发送数据到controller层参数2:发送过去的参数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 获取到页面中的一些参数参数3:回调函数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请求成功,在controller层中对应的处理方法上面返回的数据参数4:请求和返回的数据类型 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 可以是json<script type="text/javascript">/*点击修改按钮,让市场价格,售价,库存,购买显示亮起来,可以输入数字 &nbsp;*/function updateSku(skuId) {$("#m" + skuId).attr("disabled", false);$("#p" + skuId).attr("disabled", false);$("#i" + skuId).attr("disabled", false);$("#l" + skuId).attr("disabled", false);}/*获取修改后的,sku中的数据 &nbsp;*/function addSku(skuId) {var m = $("#m" + skuId).attr("disabled", true).val();var p = $("#p" + skuId).attr("disabled", true).val();var i = $("#i" + skuId).attr("disabled", true).val();var l = $("#l" + skuId).attr("disabled", true).val();//保存var url = "/product/updateSku.do";var params = {"marketPrice" : m,"skuPrice" : p,"stockInventory" : i,"skuUpperLimit" : l,"id" : skuId };$.post(url,params,function(data){alert(data.message);},"json");}</script>-------------------------------------------------------------------------------<td align="center"><input type="text" id="m${sku.id}" name="marketPrice" value="${sku.marketPrice}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="p${sku.id}" name="skuPrice" value="${sku.skuPrice}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="i${sku.id}" name="stockInventory" value="${sku.stockInventory}"disabled="disabled" size="10" /></td><td align="center"><input type="text" id="l${sku.id}" name="skuUpperLimit" value="${sku.skuUpperLimit}"disabled="disabled" size="10" /></td>-----------------------------------------------------------------------------------------------------------// 库存中的保存 @RequestMapping("/product/updateSku.do") public void updateSku(Sku sku, Model model, HttpServletResponse response) { // 修改 skuService.updateSkuByKey(sku); JSONObject jo = new JSONObject(); jo.put("message", "保存成功!"); // 将ajax请求,返回一个成功的信息 ResponseUtils.sendJson(response, jo.toString()); }
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答