Jump to content

My Ajax And Jquery Ajax

Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

Which function is better in terms of security, compatibility and functionality?My functions:

function XMLHttpFactories() {	return [		function () {return new XMLHttpRequest();},		function () {return new ActiveXObject("Msxml2.XMLHTTP");},		function () {return new ActiveXObject("Msxml3.XMLHTTP");},		function () {return new ActiveXObject("Microsoft.XMLHTTP");}	];}function createXMLHTTPObject() {	var xmlhttp = false;	var factories = new XMLHttpFactories();	for (var i=0; i<factories.length; i=i+1) {		try { xmlhttp = factories[i](); }		catch (e) { continue; }		break;	}	return xmlhttp;}var xmlhttp = new createXMLHTTPObject();function stateChanged(id){	if (xmlhttp.readyState===4){		$("#"+id).html("");		$("#"+id).html(xmlhttp.responseText);	}}function getSomething(id){// this is the specific function to do something	if (!xmlhttp) { return;	}		var url="somepage.php?id="+id+"&sid="+Math.random();	xmlhttp.open("GET",url,true);	xmlhttp.onreadystatechange = function() { stateChanged("container"); };	xmlhttp.send(null);}

jQuery code:http://code.jquery.com/jquery.jsand

<script type='text/javascript'>	$.get("somepage.php", { id: $('#some_select_box').val() }, function(data){		$("#container").html(data);		// some more stuff to do upon receiving data	}, "html");</script>

More info on jQuery AJAX can be found here: http://docs.jquery.com/AjaxPersonally I think the jQuery version should be better because I trust jQuery and it seems more compatible but what are your opinions?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...