开发者

jQuery $.get doesn't put out any data

开发者 https://www.devze.com 2023-02-11 16:42 出处:网络
what I\'m trying to do is simply catch some data from a file and insert to another file\'s (the one that that the js is in) div. It won\'t work and I can\'t seem to find the failure in here. I googled

what I'm trying to do is simply catch some data from a file and insert to another file's (the one that that the js is in) div. It won't work and I can't seem to find the failure in here. I googled for it, but it gave me no answers. Any suggestions?

jQuery:

$(document).ready(function(){

    $("li#twitter-widget a").click(function(event){

        $('<span class="loading">Lade Inhalte</span>').appendTo("div#news-widget");

        $.get("widgets/twitter.widget", function(data){
            $(data).find("div.twtr-doc").appendTo("div#news-widget");
            alert( data );
            $('span.loading').remove();
        });

    });

});

The twitter.widget

http://nopaste.info/1a6c866a15.html

The HTML that I开发者_如何学编程 want the data to be inserted to

http://nopaste.info/435800b8f8.html

The Problem

alert(data) doesn't put out anything.


jQuery injects scripts retrieved via AJAX into the DOM and removes them from the "data". Since your "twitter.widget" is nothing more than two script elements, your "data" is going to be empty.

You might want to use $.getScript instead.


You're making an ajax call to an html page? Is that page statgic or a re you trying to access one of the services in that page? Have you looked into using load instead? That will get you sections of an html I believe, wich can then be assigned to a var and appended.

http://api.jquery.com/load/

0

精彩评论

暂无评论...
验证码 换一张
取 消