【问题标题】:How to filter out "jquery.js" file in the ajax return data如何在ajax返回数据中过滤掉“jquery.js”文件
【发布时间】:2012-12-21 00:52:46
【问题描述】:

我为我的代码使用了一个 php 框架 (Yii),它在每个 html 表单中自动包含 jquery.js 以用于其验证功能。我对此无能为力。

问题出在这里:

我得到一段 html,包括表单和 jquery.js 文件,通过 ajax 显示在占位符中。 我已经在页面中有一个 jquery.js。所以第二个进来了,所有其他 jquery 插件都停止工作了,我应该重新启动它们! 我需要从我的 ajax 返回数据中过滤掉第二个 jquery.js。 我该怎么做?

jQuery.ajax({
  type: "GET",
  url: $params.url,
  data: $data,
  dataType: $dataType,
  success: function(data){
    // data includes jquery.js code
    callback(data);
  }
});

【问题讨论】:

    标签: jquery ajax filter


    【解决方案1】:

    如何使用具有以下内容的回调函数:

    callback(data.replace(/<script.+script>/, ""));
    

    【讨论】:

    • data = data.replace(/&lt;script (.*?)src="(.*?)\/(jquery.js|jquery.min.js)"(.*?)&gt;(.*?)&lt;\/script&gt;/,'');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2019-01-24
    • 2021-06-20
    • 2012-03-29
    • 1970-01-01
    相关资源
    最近更新 更多