How to stop jQuery post page refresh

二次信任 提交于 2019-12-01 23:54:31

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');
});

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

obj = jQuery.parseJSON(data);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!