Welcome to WebmasterWorld Guest from 54.167.157.247

Forum Moderators: open

Message Too Old, No Replies

Can AJAX pass HTTP queries, if so why isn't this script working?

   
1:14 am on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Below is the code for my AJAX includes, when the ajax() function is called it essentially replaces all the existing XHTML code in a layer with the XHTML from the file called.

What I'm trying to do now is use an HTTP query to tell the PHP what person the contact form will be used for. The PHP would then look at the query and if a name matches it will use their email address instead of mine. If it wasn't for this unpleasant issue I'd have gotten this working easily by now.

So again the issue that I'm certain is standing in my way is that AJAX is not passing the HTTP query to the server so the PHP does not receive the HTTP query and the form sends the email to me. I haven't made a sentence in the form of a question yet so, uh, help please?

- John

AJAX Includes Function

ajaxpage('includes/contact.php?contact=jane', 'promptsajax');

AJAX Includes JavaScript

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

[edited by: JAB_Creations at 1:15 am (utc) on Dec. 27, 2007]

3:06 pm on Dec 27, 2007 (gmt 0)

10+ Year Member



Yes, AJAX can pass paramaters in the URL.

When using "page_request.open('GET',?,?)" the recieving page(the page included by AJAX) processes the URL query paramaters just as any other page would NOT the same as receiving form fields.

You did say something about a FORM. Is the form the trigger for the AJAX call?

If the form doesn't get a "RETURN FALSE" the form itself will submit before you get returned results and will go to the action page or reload itself if action="" is empty.

Hope I understood your question and might have been helpful. :)

7:45 pm on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Disclaimer: This AJAX script is sorta-kinda-completely a copy-and-paste deal for me. ;)

Also ignore the form, it's merely the XHTML content that is called by the script and does absolutely nothing here.

I am not completely ignorant so my current (just woke up) best guess would be that I need to modify how 'bustercache' is defined?

bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

Err, regex?

I tried modifying the page_request line though the script always broke when I did anything. I'm sifting through Google at the moment trying to find something that relates to page_request.

- John

5:11 pm on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Issue Resolved: Duplicated call to the function, second one did not have the HTTP query!

- John

 

Featured Threads

Hot Threads This Week

Hot Threads This Month