Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

http request help / instruction needed...

Author Message
jonbrown



Joined: 01 Jul 2005
Posts: 56
Location: Silver Spring

Posted: Fri Aug 11, 2006 - 9:40 am    Post subject: http request help / instruction needed... Reply with quote

Hi,
I know how to do a general http request, but what I get is the entire website pulled in its entirety into the widget, which is not what I actually want. I want to be able to use an http request to grab the text from http://www.jonbrown.org/helpme.html there are three divs that have text div id 1,2 and 3. The other text items on the page are not in divs, so I do not want them displayed I simply want the http request to request the text only in these three divs, and put the contents of those divs into a div into the widget for use in the widget. For example, pull the data from these divs, and spit each one into a new div within the widget <div id="one"></div> text will be pulled from the site and thrown into the static div in the widget called <div id="text_one"></div>. I need a working example of how to simply do this in the most efficient way thanks in advance for helping!

Jon
View user's profile Send private message Send e-mail Visit poster's website Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Sat Aug 19, 2006 - 3:35 am    Post subject: A simple way... Reply with quote

If you know about http-requests (do you mean XmlHttpRequests?) where's the problem? Just get the site, use the result as xml and find the divs you want by using "getElementById"-function for example. Then put these into the widgets output-page.
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
jonbrown



Joined: 01 Jul 2005
Posts: 56
Location: Silver Spring

Posted: Sat Aug 19, 2006 - 8:58 am    Post subject: Reply with quote

I do not know much about HTTP Requests, and so I am wanting to learn more, but lacking the resources currently I am learning JS and just now getting out of Begginer mode, so HTTP Requests are now becoming more and more understandable, basically this HTTP request is the only kind I know how to use. Basically it gets the contents of a page, and dumps it into one div, basically i want to get the contents of the page, but only certain contents and put each element in its own div.

This is what I have so far...

Code:
function UpdateData () {
 var request = new XMLHttpRequest();
 request.open("GET", "http://www.jonbrown.org/helpme.html",false);
 request.send(null);
 sales = request.responseText;

  document.getElementById("sales").innerHTML = sales;

}


The problem being that this request grabs everything images, text and more. I just want to get the text elements from the page minus all the images and then be able to put those into any div in my widget that I want. Any help would be appreciated!
View user's profile Send private message Send e-mail Visit poster's website Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Sun Aug 20, 2006 - 9:40 am    Post subject: Reply with quote

I don't think there's a way to just grab certain elements of a webpage. In other words, the response always includes all the text of the website you get via XmlHttpRequest. What you want to do would be a bit easier if you could get contents of an xml-document as you could use responseXML then and look for certain tags within the XML-object.

In case of "responseText" you will probably have no other chance but to search for the portion you need via javascript. I guess there might be an easier solution using regular expressions but as I don't use them I tell you how I would do it:

1. use javascript-stringfunction indexOf to find the text '<div id="one">'
2. use the same function to find the text '</div>', starting from the position you found in the first search.
3. use javascripts substring-function to get the text you want by using the results of the functions in point 1 and 2.
4. use the result of the substring-function (which would be the text-portion within the div) and use a function like 'document.getElementById("myWidgetDiv1").innerHtml' to insert the text into a div within the widget with that id

If you need further help, then better send a mail to SGHuebner@mx.de, together with your widget if you want, and I will try to include the function mentioned above. Shouldn't be a problem.
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
jonbrown



Joined: 01 Jul 2005
Posts: 56
Location: Silver Spring

Posted: Mon Aug 28, 2006 - 9:56 pm    Post subject: Reply with quote

hi, thanks for your help, yes i understand everything, and now I have a better grasp of what you can and cant do with httprequests as a straight up response text anyway, your help was appreciated!
View user's profile Send private message Send e-mail Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group