简体   繁体   English

提交表单,无需刷新页面

[英]submit form without page refresh

is it possible to submit this php form without refreshing the page. 是否可以提交此PHP表单而无需刷新页面。 how would i go about setting a jquery code that can do this. 我将如何设置可以执行此操作的jquery代码。

<?php
   if(!isset($_POST['sthis']))
    {
?>  
<div id="show">
<form method="post" action="">
something<input name="sthis" type="text" id="sthis" />
<input name="s" type="submit" value="submit" id="submit" />
</form>
</div>
<?php
    }
     else
  {
    if(isset($_POST['sthis']))
    $sthis = $_POST['sthis'];
    if(empty($sthis)){echo 'put something in this box';}
    else echo 'ready';
  }

?>

You will need ajax for that: 你需要ajax:

$.ajax({
  type: "POST",
  url: "your url here",
  data: "sthis=someValue",
  success: function(response) {
    alert(response);
  }
});

Hope it helps 希望能帮助到你

This is how to use jQuery: 这是如何使用jQuery:

HTML HTML

<form id="frmSample">
...
</form>

<div id="divResult"></div>

JQuery JQuery的

$(function(){
  $("#frmSample").submit(function(){
    //some code here

    $("#divResult").load("yourPhpCode.php", {variableName: value, variableName1: value});
  });
});

Check out the documentation . 查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM