0

有人看到下面的问题吗?我试图让 ajaxSubmit() 工作,但第一步失败了。我的理解是,任何动作脚本(此处为 processaj.php)输出都应放入#output 元素中。我已将 processaj.php 简化为:

<?php
    error_reporting(E_ALL);
    echo ("In processaj.php");
?>

因此,当我提交某些内容时,我期望“在 processaj.php 中”会出现在#output div 中,但什么也没有出现。谢谢你的帮助..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Form Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"  type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<style>
#output {
    width: 300px;
    height:200px;
    background-color: beige;
    border:1px solid red;
    margin-top: 20px;
}

</style>
 <script>
        $(document).ready(function() {
            $('#UploadForm').on('submit', function(e) {
                e.preventDefault();
                $(this).ajaxSubmit({  
                    target: '#output'
                });
            });
        });
    </script>

</head>
<body>

    <form action="processaj.php" method="post" id="UploadForm">
        data: <input name="data" type="text" value="enter"/>
        <input type="submit"  id="SubmitButton" value="Submit" />
    </form>
    <div id="output"></div>
</body>
</html>
4

1 回答 1

1

Instead of using e.PreventDefault(), you should return false in the on submit callback function. As stated in the documentation.

$('#myForm2').submit(function() { 
    // inside event callbacks 'this' is the DOM element so we first 
    // wrap it in a jQuery object and then invoke ajaxSubmit 
    $(this).ajaxSubmit(options); 

    // !!! Important !!! 
    // always return false to prevent standard browser submit and page navigation 
    return false; 
}); 
于 2013-05-30T07:19:54.807 回答