Sign in to follow this  

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

Recommended Posts

Jose_49    608

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

Share this post


Link to post
Share on other sites
threetonesun    1,205

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.

  • Like 1

Share this post


Link to post
Share on other sites
Jose_49    608

Try to specify dataType in the get request as html:

Also, I believe if you use .load() and specify the div, it will run scripts in that div.

Let me try that out!

Share this post


Link to post
Share on other sites
Jose_49    608

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.