ajax代码不刷新页面[关闭](ajax code not refresh page [closed])

编程入门 行业动态 更新时间:2024-10-18 12:20:30
ajax代码不刷新页面[关闭](ajax code not refresh page [closed]) <form id="lets_search" action="index.php" method="post" style="width:400px;margin:0 auto;text-align:left;" role="form" target="_blank"> Search here: <br> </br> <input type="text" name="search" placeholder="Enter here" style="width:400px" /> <br> </br> <input type="submit" name="submit" value="Submit"class="w3-btn w3-padding"/> </form>

有人可以超级有用,并创建一个Ajax代码,使页面不刷新表单被提交

<form id="lets_search" action="index.php" method="post" style="width:400px;margin:0 auto;text-align:left;" role="form" target="_blank"> Search here: <br> </br> <input type="text" name="search" placeholder="Enter here" style="width:400px" /> <br> </br> <input type="submit" name="submit" value="Submit"class="w3-btn w3-padding"/> </form>

Can someone be super helpful and create ajax code that makes the page not refresh the form is submitted

最满意答案

不要使用<br></br>因为你不需要关闭这个标签; 改用<br /> 。 另外,我包含了一个关于如何使用AJAX的小例子。

$("#lets_search").on('submit', function () {
  $.post ("http://neil.computer/stack/ajax.php", $(this).serialize(), function (data) {
    console.log(data);
  })
}); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="lets_search" action="index.php" method="post" style="width:400px;margin:0 auto;text-align:left;" role="form" target="_blank">
Search here: <br /> <input type="text" name="search" placeholder="Enter here" style="width:400px" /> <br />
<input  type="submit" name="submit" value="Submit" class="w3-btn w3-padding"/> 
</form> 
  
 

Don't use <br></br> as you don't need to close this tag; use <br /> instead. Additionally, I included a small example on how to use AJAX.

$("#lets_search").on('submit', function () {
  $.post ("http://neil.computer/stack/ajax.php", $(this).serialize(), function (data) {
    console.log(data);
  })
}); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="lets_search" action="index.php" method="post" style="width:400px;margin:0 auto;text-align:left;" role="form" target="_blank">
Search here: <br /> <input type="text" name="search" placeholder="Enter here" style="width:400px" /> <br />
<input  type="submit" name="submit" value="Submit" class="w3-btn w3-padding"/> 
</form> 
  
 

更多推荐

本文发布于:2023-08-07 14:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   页面   ajax   code   closed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!