Thank you for your answers, johanafm 🙂
johanafm;10992865 wrote:This should definitely matter. Whether you use an absolute or relative path is irrelevant, but you have to stay on the same domain.
I'm aware of this. I've even moved the test file to the same subfolder as the PHP server script, and I've never called it cross-domain. I've tried every permutation I can think of (foo.com, www.foo.com, http://www.foo.com, /server.php, etc.)
Generally speaking, never ever test for browsers, no matter what way you do it (such as browser == 'Microsoft Internet Explorer'). Always test for functionality since that is what you really are after in the end. Thus
if (XMLHttpRequest)
{
return new XMLHttpRequest();
}
else
{
# Handle any browser without XMLHttpRequest, not just MSIE
# Also, IE7 does handle XMLHttpRequest iirc. At least 8 and 9 does.
}
I grabbed that from the site library which dates back to at least 2009. I can easily change it but would prefer to not fork resources and increase page load times if possible, although this is going to be used in the cart/back-end so it may not matter as much. For the purposes of testing, I can certainly rewrite createRequestObject()...
Other than that, I believe the only problem is that returning stuff from your onreadystatechange event handler is pointless. That's where you want your alert(xhr.responseText).
Does that still apply since this is a test case? I'm pretty sure that the real application will need the data returned.
The onclick handler of the checkbox on the other hand should NOT contain an alert. There will after all be nothing to return when listLimitCheck() returns, since the XHR is performed asynchronously.
Can you explain further? What I'm really trying to do is:
When a checkbox is ticked, call server.php via AJAX and see if the user is allowed to check the box; if not, uncheck and disable the box.
I'm only running this code to see if I can even get the concept to go. So, I guess I'm confused because IE has been showing me the appropriate response in the alert().
Also note that the form element is NOT allowed to contain PCDATA or inline elements, only block level elements, which means you should wrap it all in divs, fieldssets or similar.
I suppose that might be part or all of the issue, then? FF tends to be less forgiving where standards are concerned. Would wrapping it in a {p} tag suffice?