onclick -> mysql query -> javascript; same page

后端 未结 4 1353
自闭症患者
自闭症患者 2021-01-29 03:41

I need button to begin a mysql query to then insert the results into a javacript code block which is to be displayed on the same page that the button is on. mysql queries come f

4条回答
  •  渐次进展
    2021-01-29 04:25

    For this purpose you need to learn ajax.This is used to make a request without reloading the page.so that you can make a background call to mysql

    your code will be something like that

    $("#submitbutton").live("click",function(){
    
    $.ajax({url:"yourfile"},data:{$(this).data}).done(function(data){
    //this data will in json form so decode this and use this in div 2
    var x =$.parseJSON(data);
    $("#div2").html(x.val());
    })
    })
    

    and "yourfile" is the main file which connect to server and make a database request

提交回复
热议问题