在发送ajax请求之前显示确认消息 [英] Display confirmation message before send ajax request

查看:91
本文介绍了在发送ajax请求之前显示确认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个 ajax 函数,我希望在提交表单之前显示确认符号。我应该如何添加我的条件。下面是我的代码。

I have written an ajax function where I want to display confirmation meeessage before submitting the form. How should I add with my condition. Below is my code.

$.ajax({
                        url: "UBRDashboard.aspx/GetDllValue",
                        dataType: "json",
                        type: "POST",
                        contentType: 'application/json; charset=utf-8',
                        data: JSON.stringify({ ddlOduModel: ddlOduModel, ddlAntModel: ddlAntModel, ddlOMTModel: ddlOMTModel, ddlSapID: ddlSapID, ddlVendorName: ddlVendorName, strReqID: r.d, ddlSapDescVal: ddlSapDescVal, SITE_ADD: SITE_ADD, LATITUDE: LATITUDE, LONGITUDE: LONGITUDE, ddlEQP_SEQ: ddlEQP_SEQ, txtLinkID: txtLinkID, RJ_QUANTITY: RJ_QUANTITY, USER_NAME: USER_NAME, CREATED_DATE: CREATED_DATE, LOCATIONTYPE: LOCATIONTYPE, TOWERTYPE: TOWERTYPE }),
                        async: true,
                        processData: false,
                        cache: false,
                        success: function (r) {
                            if (r.d == "OK") {
                                alert('Record Saved successfully');
                                window.location.href = "UBRDashboard.aspx";
                            }
                        },
                        error: function (xhr) {
                            alert('Error while selecting list..!!');
                            window.location.href = "ErrorPage.aspx";
                        }
                    })
                },
                error: function (xhr) {
                    alert('Error while selecting list..!!');
                    window.location.href = "ErrorPage.aspx";
                }


推荐答案

解决方法是使用 beforeSend ajax property。

The solution is to use beforeSend ajax property.


beforeSend是一个预请求回调函数,之前是
已发送。在beforeSend函数中返回false将取消
请求。

beforeSend is a pre-request callback function before it is sent.Returning false in the beforeSend function will cancel the request.



beforeSend:function(){
     return confirm("Are you sure?");
},

AJAX

$.ajax({
      url: "UBRDashboard.aspx/GetDllValue",
      dataType: "json",
      type: "POST",
      contentType: 'application/json; charset=utf-8',
      data: JSON.stringify({ ddlOduModel: ddlOduModel, ddlAntModel: ddlAntModel, ddlOMTModel: ddlOMTModel, ddlSapID: ddlSapID, ddlVendorName: ddlVendorName, strReqID: r.d, ddlSapDescVal: ddlSapDescVal, SITE_ADD: SITE_ADD, LATITUDE: LATITUDE, LONGITUDE: LONGITUDE, ddlEQP_SEQ: ddlEQP_SEQ, txtLinkID: txtLinkID, RJ_QUANTITY: RJ_QUANTITY, USER_NAME: USER_NAME, CREATED_DATE: CREATED_DATE, LOCATIONTYPE: LOCATIONTYPE, TOWERTYPE: TOWERTYPE }),
      async: true,
      processData: false,
      cache: false,
      beforeSend:function(){
         return confirm("Are you sure?");
      },
      success: function (r) {
        if (r.d == "OK") {
        alert('Record Saved successfully');
        window.location.href = "UBRDashboard.aspx";
      },
      error: function (xhr) {
             alert('Error while selecting list..!!');
             window.location.href = "ErrorPage.aspx";
      }
});

这篇关于在发送ajax请求之前显示确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆