weixin_33696106 2015-08-06 20:03 采纳率: 0%
浏览 48

使用ajax从js加载html

I'm having Problems with my AJAX call. I want to append html to an existing div:

var teaser = $(this);
var url = "http://..."

ajaxHandler.send({
  url: "//www...."
  dataFilter: function (data, type) {
    teaser.append($(data))
  }
});

The problem ist, that the URL (var url) I am sending gives a JS response like this:

document.open();
document.writeln('<div id=\"mydiv\" style=\"width:190px; height:160px\">');
document.writeln('   <img src=\"http:\/\/www.abc.gif\" width=\"190\" height=\"160\" alt=\"\" border=\"0\">');
document.writeln('<\/div>');
document.close();

I get the following error:

Uncaught Error: Syntax error, unrecognized expression: document.open();

I'm using jQuery 2.x

  • 写回答

2条回答 默认 最新

  • weixin_33682790 2015-08-06 20:34
    关注

    with an ajax request you are always getting the whole content of your request-url back (which probably also contains javascript) just like your server sends it. it doesn't execute javascript code - it just reads the sourcecode like it is returned.

    why not just put pure html into your file:

    <div id="mydiv" style="">
        <img src="http://www.example.com/my.gif">
    </div>
    

    then you should be fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果