I'm about to trying to parse a tag from the text returned by a XMLHttpRequest but I can't get it to work. I've tested it in w3schools editor (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_regexp_i) where I can it to to work when the text has no newlines but else im stuck:
<script language="javascript" type="text/javascript">
var req = new XMLHttpRequest();
req.open('GET', 'www.mysite.com/index.html', false);
req.onreadystatechange=function() {
if (req.readyState==4) {
var text = req.responseText;
var tag = /<div class='classdef'>(.*?)<div/gm;
var mt = tag.exec(text);
alert(mt);
return;
}
};
req.send(null);
</script>
At the best the alert box just writes the raw regex "/(.*?)
Anyone got a pointer to what I'm doing wrong? :)
Kind regards.
UPDATED SOLUTION
Thx for all your advice, it seems there where more than just one thing amidst in my code. My goal was to feed data into a section of a page from another page. I ended up using jquery as you suggested to achieve this:
<div id="IdOfTagToAddTo"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script>
$('#IdOfTagToAddTo').load('somePageInMyDomain.html #SomeIdOfATag');
</script>
I realise that I should have made my initial goal more clear. :S. For that im sorry as I know that always causes confusion :(. Thx a million for all the pointers you guys gave me. I'm entering the new world (for me at least :)) of jQuery from now on :).
Kind regards