The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 I have lots of AJAX functions, and all of them have the following basic lines at the beginning of each function. This uses up file space, and I was wondering if I could convert the following to a single function to include in my other AJAX functions to make my javascript file smaller. Because I would like to remove all the repetitive lines. function openPOST(){ var contentType = "application/x-www-form-urlencoded; charset=UTF-8"; var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your Browser Doesn't support AJAX."); return false; } } } } So then when the above is called, it will open a request thing, then I can send the information. So I could do this: function someFunction(){ var someValue = openPOST(); someValue.onreadystatechange = function(){ if(someValue.readyState == 4){ // Do some JavaScript Stuff } } } OK, so now I need to know what the first function "openPOST()" will have to return for a value. I also need to know if my "someFunction()" is typed correctly. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 5, 2008 Author Share Posted August 5, 2008 Does anyone know if it is possible? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.