View Single Post
Old 12-21-2012, 12:27 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
> my JS book tells me that I have to check for ActiveXObjects or something then do two different things depending on what it returns

Used to be true. But even MSIE 7 supports the standard way now. So you would only need to worry about it if you want to support MSIE 6 and before. Ancient history.

I don't know what query you want to make of your PHP code. You mentioned a product id? What will your PHP send back? Just a "YES/NO" response or info about the product?

But something like this:
Code:
function ajax( prodid )
{
    // if you want to support MSIE 6 and 5:
    var http = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    // if you don't care about IE 6 and 5:
    var http = new XMLHttpRequest();

    // rest same no matter what:
    var url = "http://www.yoursite.com/yourpage.php?productid= " + encodeURIComponent(prodid);

    http.open( "GET", url, true );
    http.send( );

    http.onreadystatechange = function( ) 
    {
        if (http.readyState==4)
        { 
            document.getElementById("productDetails").innerHTML = 
                http.status == 200 ? http.responseText : "Error getting details: " + http.status;
        }
    }
}
Would you really drag in the entire jQuery library just to replace that simple code?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote