AJAX not working due to var uri not set

Seems there are many reasons AJAX may not work. I managed to isolate my problem down to sajax_get_my_uri() in sajax.php. It wasn't returning anything. As such the uri var in the JS wasn't set, and(I'm guessing, as I don't know AJAX) the script didn't know where to send it's input. Well, anyway, I replaced

`function sajax_get_my_uri() {

global $REQUEST_URI;`

`return $REQUEST_URI;

}`

with

`function sajax_get_my_uri() {

/*global $REQUEST_URI;`

`return $REQUEST_URI;*/

return $_SERVER["REDIRECT_SCRIPT_URI"]."?".$_SERVER["REDIRECT_QUERY_STRING"];

}`

and now it works beautifully. Now, I don't know AJAX, so for all know, giving it the whole uri might be overkill, so I'll leave the actual bugfixing to Tristan.

Edit: Oh, I almost forgot, you can check if your uri variable is set by viewing the source and searching(Ctrl+F) for `uri = "`. If it just says `uri = "";` you will probably have to fix it.

Comments

  • trisweb Administrator
    Wow, interesting. Sajax always seemed kind of hacky to me. I'm looking for other libraries that might be better....
  • Yes, I also discovered that one after half a day of debugging :-)

    I put in

    function sajax_get_my_uri() {
    global $_SERVER;
    return $_SERVER['REQUEST_URI'];
    }

    and it works fine.

    I guess the reason is that $REQUEST_URI is a shortcut for $_SERVER['REQUEST_URI'], which is set in some versions of PHP and not in others.

    On a slightly different note, the debug mode cannot be activated, setting
    $sajax_debug_mode = 1
    does not work (weird, the code looks ok), so you'll have to set it in line 86 manually.

    Tobi
Sign In or Register to comment.