【问题标题】:jQuery ajax calling javascript functionjQuery ajax 调用 javascript 函数
【发布时间】:2008-12-25 09:07:47
【问题描述】:

我正在使用 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)

【问题讨论】:

    标签: javascript jquery ajax function-calls


    【解决方案1】:

    你应该在Ajax请求的回调函数中调用display函数,像这样:

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

    在上述情况下,data 是从ajax.php 收到的响应

    【讨论】:

    • 感谢 Dreas Grech,现在工作正常
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 2021-10-21
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多