jQuery: The Write Less, Do More JavaScript Library

How to make .get return only div contents

View: New views
5 Messages — Rating Filter:   Alert me  

How to make .get return only div contents

by SECSteve :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have been able to get the .get method to work and put the results in
a <div>.  My problem is that my .get calls ont he same page as it
originates from so it returns the entire page inot the <div>.  I get
the entire page with my new content inside the existing page.    How
do I get just the new content for my <div>?

Here is me code.

  function updateCompanies(alpha){
    $.get("InteractionsByCompanyr6.aspx?alpha=" + alpha
      ,""
      , function(data){
          $("div#update1").html(data);
        }
    );
  }


Thanks,
Steve

Re: How to make .get return only div contents

by Michel Belleville :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, you should consider reading the doc sometimes :
http://docs.jquery.com/Core/jQuery#expressioncontext
By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context.
$("div#update1").html($('div#update1', data));
 
And if you had read even a bit further you might have stubled on that :
http://docs.jquery.com/Ajax/load#urldatacallback
It allows you to do that :
$("div#update1").load("InteractionsByCompanyr6.aspx div#update1 > *", { alpha: alpha });
$("div#update1") is who will recieve the contents in your existing page
"InteractionsByCompanyr6.aspx div#update1 > *" says you load (using get) your asp page and just keep the contents of update1 to insert.
{ alpha: alpha } is the get parameter to happend the query
Ain't it nifty ?

Michel Belleville


2009/11/4 SECSteve <ddetto@...>
I have been able to get the .get method to work and put the results in
a <div>.  My problem is that my .get calls ont he same page as it
originates from so it returns the entire page inot the <div>.  I get
the entire page with my new content inside the existing page.    How
do I get just the new content for my <div>?

Here is me code.

 function updateCompanies(alpha){
   $.get("InteractionsByCompanyr6.aspx?alpha=" + alpha
     ,""
     , function(data){
         $("div#update1").html(data);
       }
   );
 }


Thanks,
Steve


RE: How to make .get return only div contents

by Rick Faircloth :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

You know, Michel, I’ve been reading many of your remarks recently

and have noticed that you seem to have a desire to come across as a jerk.

Maybe you want to be perceived that way…I don’t know.

 

But too many of your comments contain lines such as:

 

“Well, you should consider reading the doc sometimes:”

and

“And if you had read even a bit further you might have stubled (sic) on that:”

No reason to make such remarks…

 

Yes, reading the docs is helpful, but finding information in the docs

means knowing what to look for…and many times people don’t know

what they need.

 

You are helpful in your remarks, but you always tarnish them with

disrespect to the person you’re addressing…even those who are

posting to the list for the very first time.

 

You’re being offensive.  Cool the attitude a bit…

 

Rick

 

From: Michel Belleville [mailto:michel.belleville@...]
Sent: Friday, November 06, 2009 1:55 AM
To: jquery-en@...
Subject: Re: [jQuery] How to make .get return only div contents

 

Well, you should consider reading the doc sometimes :
http://docs.jquery.com/Core/jQuery#expressioncontext

By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context.

$("div#update1").html($('div#update1', data));
 
And if you had read even a bit further you might have stubled on that :
http://docs.jquery.com/Ajax/load#urldatacallback
It allows you to do that :
$("div#update1").load("InteractionsByCompanyr6.aspx div#update1 > *", { alpha: alpha });

$("div#update1") is who will recieve the contents in your existing page
"InteractionsByCompanyr6.aspx div#update1 > *" says you load (using get) your asp page and just keep the contents of update1 to insert.
{ alpha: alpha } is the get parameter to happend the query

Ain't it nifty ?

Michel Belleville

2009/11/4 SECSteve <ddetto@...>

I have been able to get the .get method to work and put the results in
a <div>.  My problem is that my .get calls ont he same page as it
originates from so it returns the entire page inot the <div>.  I get
the entire page with my new content inside the existing page.    How
do I get just the new content for my <div>?

Here is me code.

 function updateCompanies(alpha){
   $.get("InteractionsByCompanyr6.aspx?alpha=" + alpha
     ,""
     , function(data){
         $("div#update1").html(data);
       }
   );
 }


Thanks,
Steve

 


Re: How to make .get return only div contents

by Michel Belleville :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Point taken, thanks for pointing out.

Michel Belleville


2009/11/6 Rick Faircloth <Rick@...>

You know, Michel, I’ve been reading many of your remarks recently

and have noticed that you seem to have a desire to come across as a jerk.

Maybe you want to be perceived that way…I don’t know.

 

But too many of your comments contain lines such as:

 

“Well, you should consider reading the doc sometimes:”

and

“And if you had read even a bit further you might have stubled (sic) on that:”

No reason to make such remarks…

 

Yes, reading the docs is helpful, but finding information in the docs

means knowing what to look for…and many times people don’t know

what they need.

 

You are helpful in your remarks, but you always tarnish them with

disrespect to the person you’re addressing…even those who are

posting to the list for the very first time.

 

You’re being offensive.  Cool the attitude a bit…

 

Rick

 

From: Michel Belleville [mailto:michel.belleville@...]
Sent: Friday, November 06, 2009 1:55 AM
To: jquery-en@...
Subject: Re: [jQuery] How to make .get return only div contents

 

Well, you should consider reading the doc sometimes :
http://docs.jquery.com/Core/jQuery#expressioncontext

By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context.

$("div#update1").html($('div#update1', data));
 
And if you had read even a bit further you might have stubled on that :
http://docs.jquery.com/Ajax/load#urldatacallback
It allows you to do that :
$("div#update1").load("InteractionsByCompanyr6.aspx div#update1 > *", { alpha: alpha });

$("div#update1") is who will recieve the contents in your existing page
"InteractionsByCompanyr6.aspx div#update1 > *" says you load (using get) your asp page and just keep the contents of update1 to insert.
{ alpha: alpha } is the get parameter to happend the query

Ain't it nifty ?

Michel Belleville

2009/11/4 SECSteve <ddetto@...>

I have been able to get the .get method to work and put the results in
a <div>.  My problem is that my .get calls ont he same page as it
originates from so it returns the entire page inot the <div>.  I get
the entire page with my new content inside the existing page.    How
do I get just the new content for my <div>?

Here is me code.

 function updateCompanies(alpha){
   $.get("InteractionsByCompanyr6.aspx?alpha=" + alpha
     ,""
     , function(data){
         $("div#update1").html(data);
       }
   );
 }


Thanks,
Steve

 



Re: How to make .get return only div contents

by mkmanning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just as an FYI, it's better from a readability standpoint, and also
faster to use:

$(data).find('#update1');



On Nov 5, 10:55 pm, Michel Belleville <michel.bellevi...@...>
wrote:

> Well, you should consider reading the doc sometimes :http://docs.jquery.com/Core/jQuery#expressioncontext
>
> > By default, if no context is specified, $() looks for DOM elements within
> > the context of the current HTML document. If you do specify a context, such
> > as a DOM element or jQuery object, the expression will be matched against
> > the contents of that context.
>
> $("div#update1").html($('div#update1', data));
>
> And if you had read even a bit further you might have stubled on that :http://docs.jquery.com/Ajax/load#urldatacallback
> It allows you to do that :
> $("div#update1").load("InteractionsByCompanyr6.aspx div#update1 > *", {
> alpha: alpha });
> $("div#update1") is who will recieve the contents in your existing page
> "InteractionsByCompanyr6.aspx div#update1 > *" says you load (using get)
> your asp page and just keep the contents of update1 to insert.
> { alpha: alpha } is the get parameter to happend the query
> Ain't it nifty ?
>
> Michel Belleville
>
> 2009/11/4 SECSteve <dde...@...>
>
>
>
> > I have been able to get the .get method to work and put the results in
> > a <div>.  My problem is that my .get calls ont he same page as it
> > originates from so it returns the entire page inot the <div>.  I get
> > the entire page with my new content inside the existing page.    How
> > do I get just the new content for my <div>?
>
> > Here is me code.
>
> >  function updateCompanies(alpha){
> >    $.get("InteractionsByCompanyr6.aspx?alpha=" + alpha
> >      ,""
> >      , function(data){
> >          $("div#update1").html(data);
> >        }
> >    );
> >  }
>
> > Thanks,
> > Steve