Javascript链接加载了ajax [英] Javascript link loaded with ajax

查看:85
本文介绍了Javascript链接加载了ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ajax,我使用下面的函数'addScript'将js文件添加到加载的页面。这适用于

  addScript('SlimBox / js / mootools.js'); 

但是,如果我将Google小工具脚本链接添加到函数中,我无法使其工作。这可能以不同的方式解决吗?以下是我无法工作的代码。

 函数addScript(src)
{
var script = document.body.appendChild(document.createElement (脚本));
script.src = src;
}

...
if(xmlhttp.readyState == 4&& xmlhttp.status == 200)
{
document。的getElementById( myDivFull)的innerHTML = xmlhttp.responseText。

addScript('//www.gmodules.com/ig/ifr?url=http://www.mortgage-info.com/gadgets
/gadgetsmortgagecalculator.xml&synd = open& amp; amp; w = 250& h = 200& JS');
}

谢谢。查看原始问题: https://stackoverflow.com/a/8948846/1149557

解决方案

您正在加载的URL返回HTML,而不是JavaScript。这似乎是因为您正在使用& amp; 而不是& 。用& 替换& amp; ,这应该可以解决你的问题:

  addScript(//www.gmodules.com/ig/ifr?url=http://www.mortgage-info.com/gadgets+ 
/gadgetsmortgagecalculator.xml&synd=open&w=250&h=200&title=Mortgage+Calculator+
& border =%23ffffff%7C3px%2C1px + solid +%23999999& output = js );


With ajax I use the below function 'addScript' to add a js file to the loaded page. This works just fine with

addScript('SlimBox/js/mootools.js');

however I can not get it to work if I add a google gadget script 'link' into the function. Is this solved in a different way maybe? Below is the code I can not get to work.

function addScript(src)
{
    var script = document.body.appendChild(document.createElement("script"));
    script.src = src;
} 

...
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
   document.getElementById("myDivFull").innerHTML=xmlhttp.responseText;

   addScript('//www.gmodules.com/ig/ifr?url=http://www.mortgage-info.com/gadgets    
   /gadgetsmortgagecalculator.xml&synd=open&w=250&h=200& 
   amp;title=Mortgage+Calculator&border=%23ffffff%7C3px%2C1px+solid+%23999999&
   amp;output=js');
}

Thank you. See original question : https://stackoverflow.com/a/8948846/1149557

解决方案

The URL you are loading returns HTML, not JavaScript. This seems to be because you are using & instead of just &. Replace & with & and that should solve your problem:

addScript("//www.gmodules.com/ig/ifr?url=http://www.mortgage-info.com/gadgets" +
    "/gadgetsmortgagecalculator.xml&synd=open&w=250&h=200&title=Mortgage+Calculator" +
    "&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js");

这篇关于Javascript链接加载了ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆