How to stop jQuery post page refresh

前端 未结 2 921
太阳男子
太阳男子 2021-01-22 07:05

I am getting data from an MySQL database through PHP. I am sending the and getting the data from PHP using jQuery. Here is the code.

$.POST(\"SubmitCode.php\", $         


        
2条回答
  •  遥遥无期
    2021-01-22 07:38

    Try this instead: (note the placement of the callback function, and lowercase .post method)

    $.post("SubmitCode.php", $("#questionCodeForm").serialize(),function(data) {
      //manipulate your data here
    
     },'json');
    

    Also make sure that whatever is triggering the post isn't an actual link and if it is, you need to stop the default action from occuring. For example:

    Click here to submit
    

    javascript:

    $(a).click(function(e) { 
    e.preventDefault();
    $.post("SubmitCode.php", $("#questionCodeForm").serialize(),function(data) {
      //manipulate your data here
    
     },'json');
    });
    

提交回复
热议问题