How to call a PHP function with Ajax?

前端 未结 3 792
渐次进展
渐次进展 2021-01-25 02:34

I have a PHP function which returns an array :

function lire( $id) {
            $ret = array() ; 
            $sSQL = \"SELECT  *  FROM produit WHERE prod_code          


        
3条回答
  •  醉梦人生
    2021-01-25 03:01

    this is the response to the comment you added earlier. I couldnt format it in the comment. Sorry.

     $(document).ready(function() {
    
          $("#idofinput").blur(function(){
    
    
        var value = $.ajax({
        type: "POST",
        url: "some.php",
        data: "name="+$("#idofinput").val(),
        async: false
        }).responseText;
    
        myval= parseInt(value);
    
        if(myval>0)
        {
            //your code goes here
        }
        else
        {
        //your code goes here
        }
    
    
    
        }); 
    
        });
    

    You may attach the function with the input element on document load.

    replace the idofinput with input element id

提交回复
热议问题