Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.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/jquery/82.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 如何在API调用后和if语句内启用Submit按钮_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何在API调用后和if语句内启用Submit按钮

Javascript 如何在API调用后和if语句内启用Submit按钮,javascript,jquery,ajax,Javascript,Jquery,Ajax,在执行api调用doAjax()之后,我禁用了提交按钮#myButton 但在回调后它将无法启用。。如果回拨满足某个标准,即 $.ajax({ type: "GET", url: "api5.php", data: dataString, dataType: "json", //if received a response from the server success: function (response) { var status

在执行api调用doAjax()之后,我禁用了提交按钮#myButton

但在回调后它将无法启用。。如果回拨满足某个标准,即

 $.ajax({
    type: "GET",
    url: "api5.php",
    data: dataString,
    dataType: "json",

    //if received a response from the server
    success: function (response) {
    var status = response.status;
enter code here
if ((status == 'READY' && response.endpoints[0].statusMessage == 'Ready')) { 
$('input:submit').attr("disabled", false);

但似乎不起作用。。按钮保持禁用状态。

如果执行了块,是否起诉?尝试在if块内执行console.log或alert。此外,请尝试以下操作:

$('input:submit').removeAttr('disabled');

或者您也可以尝试输入[type=submit]作为选择器,或者提供一个类或id并使其成为选择器。

代码对我有效,只注释这一行
在此处输入代码

 $.ajax({
 type: "GET",
 url: "api5.php",
 data: dataString,
 dataType: "json",

 //if received a response from the server
 success: function (response) {
 var status = response.status;
 //enter code here
      if ((status == 'READY' && response.endpoints[0].statusMessage == 'Ready')) { 
           $('input:submit').attr("disabled", false);

Try:
$(el).prop('disabled',false)
$('input:submit').prop('disabled',false)-使用prop而不是attr基于您发布的click事件发生的情况是,当您进行ajax调用时,我假设ajax success中if语句中的代码被执行,类型为submit的输入元素被启用,但在您禁用click事件中的按钮之后不久。这就是为什么我认为你的按钮没有启用我试过了。道具也是,但没用。。如果我把它放在if语句之外,那么它就起作用了。。不知道为什么,但我在if语句中有其他数据,它们都执行了,我在页面上看到了这些数据……shrawan_lakhe,我想你可能了解到了一些事情,因为没有一个建议的解决方案似乎重新启用了按钮。我还有别的办法吗?关键是我需要在if语句中启用submit按钮if语句确实在运行,因为结果显示在页面上,唯一没有执行的是enable submit按钮…嗯,只是再试了一次,似乎您的第一个解决方案工作了$('input:submit').removeAttr('disabled');
 $.ajax({
 type: "GET",
 url: "api5.php",
 data: dataString,
 dataType: "json",

 //if received a response from the server
 success: function (response) {
 var status = response.status;
 //enter code here
      if ((status == 'READY' && response.endpoints[0].statusMessage == 'Ready')) { 
           $('input:submit').attr("disabled", false);