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

How to Enable Submit Button After API Call and Within if Statement

本文关键字:语句 启用 提交 按钮 if API 调用      更新时间:2023-09-26

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

    $("#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);

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

你是否起诉你的 if 块正在被执行?尝试在 if 块内执行控制台.log或警报。另外,请尝试以下操作:

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

您也可以尝试输入[类型=提交]作为选择器,或者给出一个类或ID并使其成为选择器。

代码对我有用,只注释这一行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);

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