Categories
javascript jquery

Using XDomainRequest object with jQuery

This primairly to work with IE9 and below. IE10+ will just use the jQuery.Ajax method.



		var leadDataObj = {
			"firstname": "Darth",
			"lastname": "Vader",
			"age": "78",
			"email": "amyourfather@hotmail.com"
		};

        if ($.browser.msie && window.XDomainRequest && parseInt($.browser.version, 10) <= 9) {
            // Use Microsoft XDR
            var xdr = new XDomainRequest();
            xdr.open("POST", "http://www.awesome-domain.com");
            xdr.onprogress = function(){
				// Do something while in progress
            }
            xdr.onload = function() {
                console.log(xdr.responseText);           
            };
            xdr.onerror = function(){
                console.log("We're sorry, an error has occurred.  Please try again");
            };
			xdr.send($.param(leadDataObj)); // Posts a query string based on the leadDataObj. This is sent as text. 
        } else {
            $.ajax({
                type: 'POST',
				url: "http://www.awesome-domain.com",
                data: leadDataObj,
                crossDomain: true,
However, discomfort from these conditions is temporary but occasional and often occurs viagra line  in cycles. To get more information about their terms  tadalafil side effects and conditions, you can visit their website. However it's being used with greater effect  buy viagra cialis now days. According to the glacialridgebyway.com discount pfizer viagra scientists, injecting a byproduct of liposuction - uncultured stormal vascular fraction in the base of the penis to maintain the erection until intercourse is finished.                 beforeSend: function(){
                    // Do something while in progress
                },
                error: function(jqXHR, data, errorThrown) {
                    console.log("errorThrown: "+ errorThrown);
                    alert("We're sorry, an error has occurred.  Please try again");
                },
                success: function(data){
					console.log(data); //same as xdr.responseText
                }
            });
        }


Server side I used PHP and generated my $_POST variables based on the $HTTP_RAW_POST_DATA sent.

if (isset($HTTP_RAW_POST_DATA)) {
    $data = explode('&', $HTTP_RAW_POST_DATA);
    foreach ($data as $val) {
        if (!empty($val)) {
            list($key, $value) = explode('=', $val);   
            $_POST[$key] = urldecode($value);
        }
    }
}