简体   繁体   English

我正在尝试使用jquery加载,但是在获取特定代码段时不允许使用脚本标签,该怎么办?

[英]I am trying to use jquery load, but that doesn't allow script tags when getting a certain piece of code, what can I do?

I was using jquery load to load html inside a div, but they don't allow script tags to be parsed when selecting a certain id from that file. 我正在使用jquery加载将html中的html加载,但是当从该文件中选择某个id时,它们不允许解析脚本标签。 I need to allow script tags to be parsed without the whole page to be loaded, how can I accomplish this. 我需要允许在不加载整个页面的情况下解析脚本标签,我该如何完成这一工作。 This was my old code: 这是我的旧代码:

$('.link_inner').click(function(e){
e.preventDefault();
var link = $(this).attr('href');
$('#content').fadeOut('slow', function(){
$("#content").load( link + " #inner_main_content", function(){
    $('#content').fadeIn('slow');
});
});

As you can see, that will not parse the script tags due to selecting parts of the external page, what is a way to allow script tags be selecting and only a certain div in the external web page 如您所见,由于选择了外部页面的一部分,因此不会解析脚本标记,这是一种允许选择脚本标记并且仅选择外部网页中特定div的方法

I ended up using an ajax request like the following 我最终使用了如下的ajax请求

$('.link_inner').click(function(e){
    e.preventDefault();
    var link = $(this).attr('href');
    $('#content').fadeOut('slow', function(){
        $.ajax({
            url: link,
            success: function(e){
               $('#content').html('e');
               $('#content').fadeIn('slow');  
            }
        });
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我试图理解这段TypeScript代码 - I am trying to understand this piece of TypeScript code 我该怎么做才能使这段代码按我的意愿工作 - what can i do to get this piece of code working as i want 尝试使用Ajax访问页面时,为什么会出现Access-Control-Allow-Origin错误? - Why am I getting Access-Control-Allow-Origin error when trying to use ajax to access a page? 我无法使用jQuery库,并且遇到TypeError:将“翻译”为纯JavaScript时document.getElementById(…)为null - I can't use jQuery library, and I am getting TypeError: document.getElementById(…) is null when 'translating' to pure javascript 尝试通过Chrome扩展js脚本使用MediaWiki API时,为什么会得到空值? - Why am I getting null value when trying to use the mediawiki api from a chrome extension js script? 我无法优化这段代码 javascript - i can't optimize this piece of code javascript 我试图比较检索到的标签与选定或创建的标签,如果标签不存在perfom post请求 - I am trying to compare the retrieved tags with selected or created tags, if tag doesn't exist perfom post request 当我在脚本中使用AJAX时,JQuery停止工作。 我究竟做错了什么? - JQuery stops working when I use AJAX in my script. What am I doing wrong? 我正在尝试创建XML和XSL,但它给我一个错误,我不知道该怎么办 - I am trying to create an XML and XSL, but it is giving me an error that I can't figure out what to do 为什么当我尝试将函数的返回值与字符串连接时我的代码不起作用? - why my code doesn't work when I am trying to concatenate a function's return value with a string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM