Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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
Javascript 在Ajax调用后,我是否可以将asp.net OnClientClick返回true?或者其他方式?_Javascript_Asp.net_Ajax - Fatal编程技术网

Javascript 在Ajax调用后,我是否可以将asp.net OnClientClick返回true?或者其他方式?

Javascript 在Ajax调用后,我是否可以将asp.net OnClientClick返回true?或者其他方式?,javascript,asp.net,ajax,Javascript,Asp.net,Ajax,我使用Ajax调用检查用户是否登录。如果没有,显示登录对话框;否则我希望OnClientClick返回true,以便表单提交。我正在考虑使用一个全局变量并检查它,直到Ajax给它一个值。。。我不确定这是不是正确的方法?谢谢 (服务器端代码已经工作) 在.ascx中: <asp:Button ID="buttonSubmit" Text="Submit" OnClientClick="return buttonSubmitOnclick()" OnClick="buttonSubmit_Cl

我使用Ajax调用检查用户是否登录。如果没有,显示登录对话框;否则我希望OnClientClick返回true,以便表单提交。我正在考虑使用一个全局变量并检查它,直到Ajax给它一个值。。。我不确定这是不是正确的方法?谢谢

(服务器端代码已经工作)

在.ascx中:

<asp:Button ID="buttonSubmit" Text="Submit" OnClientClick="return buttonSubmitOnclick()" OnClick="buttonSubmit_Click" runat="server"/>

当条件满足时,您可以使用
document.forms['myForm'].submit()
在ajax调用响应时手动提交表单。 将按钮设置为正常的按钮(非提交按钮)并在按钮元素中的功能调用之前移除返回按钮,然后执行以下操作:

function buttonSubmitOnclick() {
  showLogin();
  }


//========== Ajax ==============

function showLogin() {
  var xmlhttp;

  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  }
  else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        if (xmlhttp.responseText === "false") {
            $find('modalPopupLogin').show(); // display the pop up
        }else{
        document.forms['myForm'].submit() // else submit the form,'myForm' is form id'
            }
    }
  }
  xmlhttp.open("GET", "AjaxService.aspx?t=auth", true);  
  xmlhttp.send();
}

这不管用。。。showLogin()本身不返回任何内容。。。它是onreadystatechange返回true/false
function buttonSubmitOnclick() {
  showLogin();
  }


//========== Ajax ==============

function showLogin() {
  var xmlhttp;

  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  }
  else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        if (xmlhttp.responseText === "false") {
            $find('modalPopupLogin').show(); // display the pop up
        }else{
        document.forms['myForm'].submit() // else submit the form,'myForm' is form id'
            }
    }
  }
  xmlhttp.open("GET", "AjaxService.aspx?t=auth", true);  
  xmlhttp.send();
}