【问题标题】:Parsing Ajax response of a php file and calling a javascript function解析 php 文件的 Ajax 响应并调用 javascript 函数
【发布时间】:2014-01-08 15:25:05
【问题描述】:

我想在 php 文件上调用一个函数,我在 ajax 中调用该函数。 我尝试了以下代码:

$("#jq_entryConfQuickSend").click(function () {
    $.ajax({
        type: "GET",
        context: document.body,
        //async:false,
        url: RP_ROOT_PATH + "/courriers/entries_courriers/rp_win_courrierEntryConfirmation.php",
        data: "id_client=" + RP_CLIENT.rp_clientID,
        success: function (responseText) {
            //var json = eval("(" + responseText + ")");
            $("#response-div").html(responseText);
            $(responseText).find("script").each(function (i) {
                eval($(this).text());
                console.log('result');
            });
        }
    });
});

$(responseText) 似乎是 chrome 调试器中的一个数组(我可以看到下面的 e.fn.e.init[58]),但是当我尝试使用 find('script') 函数时,它没有什么都不退?? 而且我在这些文件中有很多脚本标签???

问题:什么是 e.fn.e.init[]? 如何在我刚刚在 ajax 中加载的文件上调用我的 javascript 函数 谢谢你

【问题讨论】:

  • e.fn.e.init 是您在 console.log jQuery 对象时看到的内容。
  • 您是否尝试检索从 PHP 文件返回的脚本标签,然后在页面中执行它们?
  • 我在另一个主题中找到了答案:[如果有人感兴趣][1] [1]:stackoverflow.com/questions/4733086/…

标签: javascript php jquery ajax


【解决方案1】:

在我需要包含的 ajax 参数中:

dataType: "html"

那么就可以从响应中调用函数了

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2010-11-06
    相关资源
    最近更新 更多