Why does IE complain about this javacript call?
$.get("profile_completeness.php?id=<?php echo($user_id); ?>", function(data) {
var percentage = data.match(/id="percentage_complete" value="(\d+)"/)[1];
alert(percentage);
})
This works fine in Chrome, and FF but IE throws an exception.
Here is the error I get:
Unable to get value of the property '1': object is null or undefined.
If I remove the var percentage line the error is gone.
Any ideas why?
The reason is that the variable
datadoesn’t contain what you think that it does.This works just fine in IE:
If you have created the string by using
innerHTML, it will differ somehwat depending on the browser. You won’t get the original HTML code that the elements were created from, instead the browser recreates HTML code from the DOM elements, and each browser have different ways of formatting the HTML code.