[RESOLVED] Using Ajax.open to get specific div |
Author: |
Message: |
macgyver08
Junior Member
Hakuna matata!
Posts: 23
34 / /
Joined: Feb 2007
|
O.P. [RESOLVED] Using Ajax.open to get specific div
I know a little javascript to get me by on small projects, but I'm new to Ajax. I've looked at all the threads on this site with "Ajax.open" but I can't figure out what to do.
I want to use Ajax in a Plus! Live script* to get the text between a specific div tag on this page...
http://macgyver89.webs.com/ajax_test.html
and then send it to a user through an instant message*. "1. test111" is between <div id="1"></div>, and so on.
Can anyone help?
I want it to do something like this script (click here). Instead of the text on the site being grabbed and being displayed in a personal message though, I want the text (from a specific div) on my site to be sent through an instant message on command.*
* = edited
This post was edited on 01-30-2010 at 12:07 AM by macgyver08.
|
|
01-27-2010 06:57 AM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: Using Ajax.open to get specific div
what do you mean send it to a user? e-mail?
I would suggest jquery (javascript library) would be probably the best way to do this as it has a built in, simple ajax function and selectors to get the right element easily (very flexible) and a function to read the contents of the div...
Although, if you do want to use email, You'd need to find a way to pass the javascript variable to PHP, which IIRC needs to be done through some sort of form.
<Eljay> "Problems encountered: shit blew up"
|
|
01-27-2010 08:08 AM |
|
|
macgyver08
Junior Member
Hakuna matata!
Posts: 23
34 / /
Joined: Feb 2007
|
O.P. RE: RE: Using Ajax.open to get specific div
quote: Originally posted by Spunky
what do you mean send it to a user? e-mail?
I would suggest jquery (javascript library) would be probably the best way to do this as it has a built in, simple ajax function and selectors to get the right element easily (very flexible) and a function to read the contents of the div...
Although, if you do want to use email, You'd need to find a way to pass the javascript variable to PHP, which IIRC needs to be done through some sort of form.
Thanks for replying
No, not e-mail, through an instant message.
I've never heard of jquery, so I don't know if I'd even know how to use it, but look at this script:
http://shoutbox.menthix.net/showthread.php?tid=73...d=810875#pid810875
I want it to do something like that. Instead of the text on the site being grabbed and being displayed in a personal message though, I want the text (from a specific div) from my site to be sent through an instant message on command.
This post was edited on 01-27-2010 at 09:58 AM by macgyver08.
|
|
01-27-2010 09:57 AM |
|
|
djdannyp
Elite Member
Danny <3 Sarah
Posts: 3546 Reputation: 31
38 / /
Joined: Mar 2006
|
RE: Using Ajax.open to get specific div
quote: Originally posted by macgyver08
This is a scripting question! Some mod moved it from
Scripting to Tech Talk for some reason, so don't ask
why I posted it here, because I didn't.
The scripting section of the website is for Messenger Plus! Live scripting. Your question is a "Tech Talk" enquiry as it isn't to do with Messenger Plus! Live, it's just general technology enquiry
|
|
01-27-2010 10:49 AM |
|
|
macgyver08
Junior Member
Hakuna matata!
Posts: 23
34 / /
Joined: Feb 2007
|
O.P. RE: RE: Using Ajax.open to get specific div
quote: Originally posted by djdannyp
quote: Originally posted by macgyver08
This is a scripting question! Some mod moved it from
Scripting to Tech Talk for some reason, so don't ask
why I posted it here, because I didn't.
The scripting section of the website is for Messenger Plus! Live scripting. Your question is a "Tech Talk" enquiry as it isn't to do with Messenger Plus! Live, it's just general technology enquiry
Hmm...the solution to my problem was going to be utilized in a Plus! Live script. I guess I didn't make that clear. Well...wherever you think it fits best in is fine I suppose. I was just afraid that most of the scripting people would be in the scripting section, and that my question wouldn't get the best attention being in Tech Talk.
Thanks.
This post was edited on 01-27-2010 at 11:12 AM by macgyver08.
|
|
01-27-2010 11:05 AM |
|
|
Adeptus
Senior Member
Posts: 732 Reputation: 40
Joined: Oct 2005
|
RE: Using Ajax.open to get specific div
I think that you may be looking at this the wrong way. Instead of parsing your site to extract the text from a specific <div> it may be much simpler to have your site provide the same text in a more handy format, such as a .txt file or a web service. If it is "your" site, you should have the ability to set this up.
If it isn't your site, the functionality you are talking about is called "web scraping" and looking that up may yield some helpful information.
|
|
01-28-2010 07:59 AM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: Using Ajax.open to get specific div
A simple and crude method would just to be:
Javascript code:
// txt is the xmlhttp responseText stored in a variable
txt = txt.split('<div id="1">')[1];
txt = txt.split('</div>')[0];
// txt will now be the div contents including the html
// if the content is bold for example, you will see:
// This is the <b>content</b> from the div
EDIT:
It may be possible to do this in one line:
Javascript code:
txt = txt.split('<div id="1">')[1].split('</div>')[0];
I can't be sure of that one though without trying it, but most javascript seems to chain quite well
This post was edited on 01-28-2010 at 09:47 AM by Spunky.
<Eljay> "Problems encountered: shit blew up"
|
|
01-28-2010 09:45 AM |
|
|
macgyver08
Junior Member
Hakuna matata!
Posts: 23
34 / /
Joined: Feb 2007
|
O.P. RE: Using Ajax.open to get specific div
quote: Originally posted by Adeptus
I think that you may be looking at this the wrong way. Instead of parsing your site to extract the text from a specific <div> it may be much simpler to have your site provide the same text in a more handy format, such as a .txt file or a web service. If it is "your" site, you should have the ability to set this up.
If it isn't your site, the functionality you are talking about is called "web scraping" and looking that up may yield some helpful information.
quote: Originally posted by Spunky
A simple and crude method would just to be:
Javascript code:
// txt is the xmlhttp responseText stored in a variable
txt = txt.split('<div id="1">')[1];
txt = txt.split('</div>')[0];
// txt will now be the div contents including the html
// if the content is bold for example, you will see:
// This is the <b>content</b> from the div
EDIT:
It may be possible to do this in one line:
Javascript code:
txt = txt.split('<div id="1">')[1].split('</div>')[0];
I can't be sure of that one though without trying it, but most javascript seems to chain quite well
Thanks to both of you! I've got it figured out now
|
|
01-28-2010 10:46 AM |
|
|
|