2 Replies - 1081 Views - Last Post: 16 March 2013 - 02:50 AM

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Viewing HTML loaded into a div

Posted 15 March 2013 - 07:18 AM

Hi all,

For my current project I'm required to load the contents of a URL into a div using JQuery because we're moving away from using frames so we can start being compatible with more browsers and devices. The problem is, there doesn't seem to be a way to view the HTML that's being placed into the div. I need to make sure it's valid and doesn't contain anything extra, and I can't run it through the W3C validators if I can't get to it.

Is there any way, using JQuery or some other trick, that I could actually see the HTML I'm loading into these divs?

(And before anyone says this is a bad idea -- yes, I know it's awful. I would have just rewritten everything as a new page without frames if I had the choice.).

Thanks,
Zel2008

EDIT -- Darn it, of course I find the answer with just a little more research. If it helps anybody, you can create a nifty little function that pops up your HTML as an alert, then pop it in the validators, like so:

function test_my_html( url ) {
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.send(null);
var page = req.responseText;
alert( page );
}


This post has been edited by Zel2008: 15 March 2013 - 07:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Viewing HTML loaded into a div

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6076
  • View blog
  • Posts: 23,543
  • Joined: 23-August 08

Re: Viewing HTML loaded into a div

Posted 15 March 2013 - 08:01 AM

Do yourself a favor and use some browser-based JS debugger. It will be much cleaner than popping alerts.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,329
  • Joined: 08-June 10

Re: Viewing HTML loaded into a div

Posted 16 March 2013 - 02:50 AM

expanding on that, if you do an AJAX request (either in vanilla JS or in jQuery or anything other), the Browsers’ dev tools can show you the received AJAX response (and all its content).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1