Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从具有$.Ajax()方法的javascript函数返回状态值_Javascript_Asp.net - Fatal编程技术网

如何从具有$.Ajax()方法的javascript函数返回状态值

如何从具有$.Ajax()方法的javascript函数返回状态值,javascript,asp.net,Javascript,Asp.net,我有一个java脚本函数,它返回status的值。我的职能如下: function IsReportAlreadyExists() { var result=true; $.ajax({ type: "POST", url: "ReportDetail.aspx/CheckReport", data: "{}", cont

我有一个java脚本函数,它返回status的值。我的职能如下:

function IsReportAlreadyExists() {
            var result=true;
            $.ajax({
                type: "POST",
                url: "ReportDetail.aspx/CheckReport",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d != "") {
                       result= confirm(msg.d);
                    }
                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
            return result;
        }
我在asp.net按钮控件的客户端单击事件上调用此函数

 <asp:Button ID="btnSave" Style="margin-right: 10px" runat="server" CausesValidation="false"
                                                    OnClick="btnSave_Click" Text="Save" Width="70px" OnClientClick="return IsReportAlreadyExists();" />

在客户端点击按钮时,javascript函数总是返回一个真值。我的意思是我没有得到由confirm(msg.d)设置的结果值。有什么方法可以做到这一点吗?请帮帮我,伙计们。我们将非常感谢你的帮助


谢谢,Rajbir

因为代码是异步的。首先,它返回result=true,然后在ajax调用完成后,结果被更改。您需要在成功回调中处理您的结果。

重复的和许多其他的。您能给我举个例子吗。实际上我以前没有使用过回调函数。@RajbirSingh在你的代码
success:function(msg){if(msg.d!=“”){result=confirm(msg.d);}}
中是一个回调函数