duanduan8439 2015-01-15 19:54
浏览 44

Ajax调用不保存表单信息

I have tried using the code below to save and display information using ajax. But it doesn't work.

Here's the code.

<?php session_start();?>
<html>
<head>
<script src="style/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
<script src="style/jquery-1.11.1.min.js"></script> 

<script>
$(function() {
$("#ajaxquery").live( "submit" , function(){
    // Intercept the form submission
    var formdata = $(this).serialize(); // Serialize all form data

    // Post data to your PHP processing script
    $.post( "show.php", formdata, function( data ) {
        // Act upon the data returned, setting it to #success <div>
        $("#success").html ( data );
    });

    return false; // Prevent the form from actually submitting
})
});
</script>

</head>

<form id="ajaxquery" method="post" action="">
<label for="field">Type Something:</label>
<input type="text" name="field" id="field" value="" />
<input type="submit" value="Send to AJAX" />
</form>

<div id="success"> </div>
</html>

AND MY show.php which displays data in id="success"

<?php
// Process form data
echo '<strong>You submitted to me:</strong><br/>';
print_r( $_REQUEST );

?>

Please help...

  • 写回答

1条回答 默认 最新

  • dougaicha5258 2015-01-15 20:11
    关注

    at first you have to load jquery ui after jquery

    <script src="style/jquery-1.11.1.min.js"></script> 
    <script src="style/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
    

    then in this case you don't need to use live you can simply do this

    $("#ajaxquery").submit(function(){
        // your code
    })
    

    "live" function ( or for now "on" ) used when you going to create or load html code after you set events.

    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装