Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: AJAX includes unable to pass HTTP query via GET method!

  1. #1
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Question AJAX includes unable to pass HTTP query via GET method!

    Below is the AJAX script and an example function. The function works with the HTTP query though it's not passed from the AJAX script. The script itself merely loads XHTML content from a file on the server in to an element (in the example function below it's loaded in to the element with the id of promptsajax). I have to admit that fixing this script is a bit over my head.

    AJAX Function Example
    ajaxpage('includes/contact.php?contact=frank', 'promptsajax');
    AJAX Includes Script
    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
    }
    }
    }

  2. #2
    Join Date
    Dec 2007
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    u mean that u can't add new ajax mod in this content?

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Can you provide a link to your page?

  4. #4
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    My site is http://www.jabcreations.com/

    The AJAX script is what I use to load XHTML in to the prompt (click on site options menu (once inside look at the top right) and that layer is what I refer to as the prompt). If you watch closely at the status bar for the anchors when you tab through them you'll see those anchors are all JavaScript functions that essentially keep calling different AJAX pages in to the prompt. It's one of the ways I've minimized bandwidth.

  5. #5
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by XAKERA View Post
    u mean that u can't add new ajax mod in this content?
    I can include a page like page.php but not page.php?http_query_property=http_query_value. If I do that it gets lost in the script, but it would work fine if I didn't use AJAX...but that defeats the purpose of using AJAX! I haven't found anything online ... using my best understanding of the terminology though I am not advanced enough to also understand how to necessarily approach this to the extent of making an educated guess of what (JavaScript) else I could search for in the search engines in hopes of making a lucky find.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Oddly enough:

    Code:
    page.php?http_query_property=http_query_value
    Would probably be fine, literally. But, I'm pretty sure that you mean something like:

    Code:
    page.php?page=http://www.jabcreations.com/thispage.php?bob=apples
    If so, you could do:

    Code:
    page.php?page=http%3A//www.jabcreations.com/thispage.php%3Fbob%3Dapples
    If anything would work here, that should. That is, if I've understood the problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Well your suggestions gave me the idea to try loading the page via it's absolute path (which defeats the purpose of local testing) but it still did not work...not sure what your other suggestions were based on though?

    The script needs to somehow be modded to allow HTTP queries and I'm not that JavaScript savvy just yet.

    So this looks like regex in JavaScript simpleton terms, does anything here look counter-productive?

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

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The bustcacheparameter will add a query variable with a unique value to the URL. It shouldn't affect any existing query string as it will add this using the & character if a query string already exists. Since you are having problems in this area though, and this does affect the query string, you could always disable it to see if that helps:

    Code:
    var bustcachevar=0 //bust potential caching of external pages after initial request? (1=yes, 0=no)
    However, I believe the correct approach is to escape the query string as indicted in my previous post. You need not use the absolute path, but the string should be escaped.

    Disabling bustcacheparameter and escaping, or just disabling bustcacheparameter may be required, if either and you need the bustcacheparameter functionality, it could be rewritten to be inserted as the first query var/value pair in all cases if that would help. However, if bustcacheparameter creates a problem merely by being present, even on URL's with simple existing queries, there is something wrong with the 'receiving' PHP.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    It would help if people kept the script's credits in tact!

    So I did a Google Search and found a page giving credit to this script...only it included the credits!

    My interest has started to include this script now though it lacks the ability to target an ID (from a casual look) and I *just* got a reply as I'm writing this...
    http://www.dynamicdrive.com/dynamici...jaxroutine.htm

    Here is my receiving PHP...
    <?php if (isset($_GET['name'])) {echo 'name_is_' . $_GET['name'];}
    else {echo 'not set<br />';}
    ?>
    I'm no PHP guru though I don't necessarily see anything wrong with that. I've set the bustcacheparameter to 0 and escaped the HTTP query parameter as so...
    ajaxpage('includes/contact.php\?nameis=john', 'promptsajax');
    I'm happy to at least know where the script is from now! I'm checking out the other examples...I really hope I can get this to work! Thanks for posting with such great timing!

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That receiving PHP is looking for 'name'. You are sending it 'nameis'. It will never find that.

    And, that's just a simple query and shouldn't even need escaping. Escaping is only for those query values that include special URL characters, as in the example from my first post in this thread where I asked if that was the problem.

    Try:

    Code:
    <?php if (isset($_GET['nameis'])) {echo 'name_is_' . $_GET['nameis'];}
    else {echo 'not set<br />';}
    ?>
    And make sure that part works even when not using Ajax.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •