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.

    评论

报告相同问题?