zoukankan      html  css  js  c++  java
  • Ajax请求在IE和Google Chrome中可以响应,在Firefox中无法响应

    在工作中碰到这么一个问题,发送ajax请求,在IE和chrome中可以正常的响应,但是在Firefox中无法响应,代码如下:

    JS代码:

     1  function Sure(obj) {
     2             var statu = confirm("是否确认删除?");
     3             if (!statu) {
     4                 return false;
     5             }
     6             var objOrderID = obj.id;
     7             $.ajax(
     8             {
     9                 type: "Post",
    10                 url: "/AjaxDeleteMyOrder.aspx",
    11                 data: "id=" + objOrderID + "",
    12                 dataType: "text",
    13                 success: function (data) {
    14                     //返回的数据用data.d获取内容
    15                     alert("删除订单成功");
    16                 },
    17                 error: function (err) {
    18                 }
    19             });
    20             window.location.href = "ServiceSaleList.aspx";
    21         }

    经过反复测试发现:原来是因为发送了正确的ajax请求,但是请求还没有发送出去就已经刷新的当前的页面。

    解决办法:1、将刷新页面的请求放在回调函数中运行。2、发送的ajax请求改为同步请求。

    JS代码:

     1  function Sure(obj) {
     2             var statu = confirm("是否确认删除?");
     3             if (!statu) {
     4                 return false;
     5             }
     6             var objOrderID = obj.id;
     7             $.ajax(
     8             {
     9                 type: "Post",
    10                 url: "/AjaxDeleteMyOrder.aspx",
    11                 data: "id=" + objOrderID + "",
    12                 dataType: "text",
    13                 success: function (data) {
    14                     //返回的数据用data.d获取内容
    15                     alert("删除订单成功");
    16                     window.location.href = "ServiceSaleList.aspx";
    17                 },
    18                 error: function (err) {
    19                 }
    20             });
    21         }
  • 相关阅读:
    使用 libevent 和 libev 提高网络应用性能
    An existing connection was forcibly closed by the remote host
    各种浏览器的兼容css
    vs输出窗口,显示build的时间
    sass
    网站设置404错误页
    List of content management systems
    css footer not displaying at the bottom of the page
    强制刷新css
    sp_executesql invalid object name
  • 原文地址:https://www.cnblogs.com/soulmate/p/5404063.html
Copyright © 2011-2022 走看看