By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

HTML of URL into a JS variable

P: 2
Hi, thanks for reading. I'm trying to come up with a Javascript function that would convert the HTML source of a page at a specific URL into a variable, so that the whole thing would become editable. The complication is, the URL does not end with a "html, htm, aspx" extension, but instead with a string of input form variables (i.e. ?type=AAA&color=BBB...). Hence the XMLHttpRequest method is out of question.

Is this doable in JS/jQuery at all? Thank you.
Jan 5 '12 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
Hence the XMLHttpRequest method is out of question.
why is that? as long as it is a valid URI, you can request it with XMLHttpRequest.
Jan 5 '12 #2

P: 2
Hi, thanks for the reply. I have tried this method using the following code, but to no avail. It only recognizes locally stored web pages, but not the ones accessed via http.

Expand|Select|Wrap|Line Numbers
  1. var http; 
  2. if (window.XMLHttpRequest) {
  3. http = new XMLHttpRequest();
  4. } else {
  5. try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
  6. try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
  7. http = false; } }
  8. }
  9.  
  10. function getUrl(url) {
  11. http.open("GET",url,false);
  12. http.send();
  13. return http.responseText;
  14. }
Jan 8 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
are you calling the web site from a server or directly from file? you may have an issue with SOP (Same Origin Policy).
Jan 8 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.