0

我正在使用 jQuery 和 Ajax。

我的 MainFile 有以下代码:

<html>
    <head>
        <script src="Myscript.js">
        </script>
        <script type="text/javascript">
            $(document).ready(function(){
                $.ajax({
                    type: 'POST',
                    url: 'ajax.php',
                    success: function(data){
                        $("#response").html(data);
                    }
                });
            });
        </script>

    <body>
        <div id="response">
        </div>
    </body>
</html>

我的 ajax.php 获取示例数据

...
MyScript.js has the following

function display (text,corner)
{

}
..

我有 Myscript.js。在此,我有一个名为display(text,corner). 我必须在执行 ajax.php 后调用这个函数。

我如何在 jQuery 中为上述代码执行此操作?

是否可以在 ajax.php 之后决定执行顺序并调用display(text,corner)

4

1 回答 1

1

您应该display在 Ajax 请求的回调函数中调用该函数,如下所示:

$.ajax({
    type:'POST',
    url: 'ajax.php',
    success: function(data){
        display(data, /* your other parameter, corner */); //Invoking your data function
    } 
});       

在上述情况下,data是从ajax.php

于 2008-12-25T09:13:52.197 回答