日期:2014-05-16  浏览次数:20335 次

jquery中ajax的回调函数问题。
我想完成这样的功能,应该怎么改呢? 
高手帮忙,在此谢过!

test.html
HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title> New Document </title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
         </head>
<body>
        <form method="post" action="test.php">
            <input type="text" id="m_id"/>
            <input type="submit" onclick="return preSubmit()"/>
        </form>
        <script type="text/javascript">
            function preSubmit(){
                var mID = $("#m_id").val();
                $.ajax({
                    type : "GET",
                    cache : false,
                    url : "test.php?id="+mID,
                    dataType : 'text',
                    success: function (data){
                        if(data == 1){
                            return false;
                        }else{
                            return true;
                        }
                    }
                });
                return false;
            }
        </script>
    </body>
</html>
        



test.php

PHP code

<?php
    if(isset($_POST['id']))
    {
        echo $_POST['id']."已提交";
    }
    $id = $_GET['id'];
    echo $id;



调试的时候显示没有执行,回调函数,那么问题就来了,什么时候执行的呢?

------解决方案--------------------
自己解决了啊。