如何在API调用之后和if语句中启用提交按钮

时间:2015-04-09 05:22:09

标签: javascript jquery ajax

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

    $("#myButton").click(function (e) {
    doAjax();
    $('input:submit').attr("disabled", true);
});

但它在回调后不会启用..如果回叫符合某个标准,我想启用它,即

 $.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);

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

3 个答案:

答案 0 :(得分:1)

你起诉你的if块被执行了吗?尝试在if块中执行console.log或alert。另外,请尝试以下方法:

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

或者你也可以尝试输入[type = submit]作为选择器或者给出一个类或id并使它成为选择器。

答案 1 :(得分:0)

该代码适用于我,仅对此行enter code here

进行评论
 $.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);

答案 2 :(得分:0)

尝试:$(el).prop('disabled', false)