Shoutbox

[RESOLVED] Using Ajax.open to get specific div - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [RESOLVED] Using Ajax.open to get specific div (/showthread.php?tid=93679)

[RESOLVED] Using Ajax.open to get specific div by macgyver08 on 01-27-2010 at 06:57 AM

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


RE: Using Ajax.open to get specific div by Spunky on 01-27-2010 at 08:08 AM

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.


RE: RE: Using Ajax.open to get specific div by macgyver08 on 01-27-2010 at 09:57 AM

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.
RE: Using Ajax.open to get specific div by djdannyp on 01-27-2010 at 10:49 AM

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 :)
RE: RE: Using Ajax.open to get specific div by macgyver08 on 01-27-2010 at 11:05 AM

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.
RE: Using Ajax.open to get specific div by Adeptus on 01-28-2010 at 07:59 AM

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.


RE: Using Ajax.open to get specific div by Spunky on 01-28-2010 at 09:45 AM

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
RE: Using Ajax.open to get specific div by macgyver08 on 01-28-2010 at 10:46 AM

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 :D