• 0

How do I use the JavaScript from a file I included using jQuery through GET


Question

Hi people. I know, after some Googling, that it is possible to manipulate a loaded content through Ajax and interact with it, with:


$(document).ajaxComplete(function(){
// fire when any Ajax requests complete
})
[/CODE]

But what I want is the following:

[CODE]
$.get('http://thepath.to/my/site/and/file.php', function(data)
{
var content_s = $(data).find('#cds_global');
$('#dlm_btn_settings').html(content_s)

});
[/CODE]

I want to load a page. From that page, I would like to get a specific <div> hence the ".find" function.

Now, from that <div> whose ID is "cds_global" (Without quotes), I would like to get ALL HTML + JavaScript functionality.... How do I do that?

Edit: BTW, thanks a lot in advanced :p

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Try to specify dataType in the get request as html:

dataType The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html)

Also, I believe if you use .load() and specify the div, it will run scripts in that div. If all you're doing with the data returned is pulling out a single div, .load() is the better call to use.

Link to comment
Share on other sites

  • 0

When calling .load() using a URL without a suffixed selector expression' date=' the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed. An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.


$('#a').load('article.html');
[/CODE]

However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:

[CODE]
$('#b').load('article.html #target');
[/CODE]

[/quote']

:D.

I made it work. I just pinpoint it directly without grabbing the portion I wanted!

[CODE]
$('#dlm_btn_settings').load('http://where.my/file/resides/file.php.php');
[/CODE]

Thanks a lot threetonesun!!!! :D

  • Like 1
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.