Check if AJAX response data is empty/blank/null/undefined/0

前端 未结 5 755
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 23:57

What I have:

I have jQuery AJAX function that returns HTML after querying a database. Depending on the result of the query, the function will either return HTML co

5条回答
  •  轮回少年
    2020-12-23 00:08

    This worked form me.. PHP Code on page.php

     $query_de="sql statements here";
     $sql_de = sqlsrv_query($conn,$query_de);
          if ($sql_de)
          {
            echo "SQLSuccess";
           }
             exit();
    

    and then AJAX Code has bellow

    jQuery.ajax({
                        url  : "page.php",
                        type : "POST",
                        data : {
                                buttonsave   : 1,
                                var1         : val1,
                                var2         : val2,
                                  },
                      success:function(data)
                               {
                         if(jQuery.trim(data) === "SQLSuccess")
                                       {
                               alert("Se agrego correctamente");
                              // alert(data);
                                          } else { alert(data);}
                                  },
                       error: function(error)
                               {
                        alert("Error AJAX not working: "+ error );
                                  } 
                   }); 
    

    NOTE: the word 'SQLSuccess' must be received from PHP

提交回复
热议问题