HaLo2FrEeEk Posted July 23, 2007 Share Posted July 23, 2007 I have an AJAX script that works perfectly...when what you're doing doesn't require any dynamic...ness. I want to be able to pass parameters to the script that the url being run by the AJAX can recieve. Right now, it's set up so only one page can really make anything of it. What I want is to be able to pass different values depending on what the page I'm running is, so I need your guys' expertise, I have one idea in mind but its not very practical, I was hoping you guys could help me out and tell me the what the best way would be to do what I'm trying to do. Here is my script: var http_request = false; var obj; function makePOSTRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", parameters.length); http_request.setRequestHeader("Connection", "close"); http_request.send(parameters); } function loading() { var load; load = document.getElementById("loading"); vis = load.style; if(vis.display == '' || vis.display == 'block') { vis.display = 'none'; } else if(vis.display == 'none') { vis.display = 'block'; } } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; //document.getElementById('status').innerHTML = result; obj.innerHTML = result; loading(); } else { alert('There was a problem with the request.'); loading(); } } } function get(url, user_id, div_id) { var poststr = "user_id=" + user_id + "&url=" + escape(encodeURI(document.getElementById('url').value)); obj = document.getElementById(div_id); loading(); makePOSTRequest(url, poststr); } Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted July 24, 2007 Author Share Posted July 24, 2007 Guys, I really need help, I can't figure this out on my own and I'm almost past my deadline. Please. 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.