How to stop jQuery post page refresh

前端 未结 2 910
太阳男子
太阳男子 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:21

    You also have to parse the json on the client side. You can do this using

    obj = jQuery.parseJSON(data);

    0 讨论(0)
  • 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:

    <a href="submit.php">Click here to submit</a>
    

    javascript:

    $(a).click(function(e) { 
    e.preventDefault();
    $.post("SubmitCode.php", $("#questionCodeForm").serialize(),function(data) {
      //manipulate your data here
    
     },'json');
    });
    
    0 讨论(0)
提交回复
热议问题