Jump to content

mod_rewrite messing up my ajax?


andyrue

Recommended Posts

I've been trying to get ajax working on my site, and I finally figured out why I was having such a hard time with it.  I'm using mod_rewrite to make my URLs look like /game/title instead of game.php?title=Yada_Yada

 

this is my .htaccess file

 

RewriteEngine on

RewriteBase /

RewriteRule ^game/([^/\.]+)/?$ /game.php?title=$1 [L]

 

if I browse to game.php?title=Yada_yada    my Ajax works great...

 

if I browse to game/yada_yada    my ajax doesn't work.

 

The error I get in Fire Bug is: "xajax_processForm is not defined"

 

I'm using xajax, and registering the function processForm, but it's not working with mod_rewrite.

 

Any ideas how I can fix this?  I'm sure it's just a path problem, but I don't know what to do.

 

Thanks

 

Link to comment
Share on other sites

Here is one of my functions

 

require ("./xajax.inc.php");

function processForm($aFormData,$id)  {  

$who_SQL = "SELECT * FROM who_said WHERE id = '$aFormData[suggest]'";
dbConnect("quotes");
$who_results = mysql_query($who_SQL);
$who_row = mysql_fetch_assoc($who_results);

    $sOut .= "<p>Thank You.  Your vote for <strong>". $who_row['who_said']."</strong> has been recorded.</p>";

    $objResponse = new xajaxResponse();
    
    $objResponse->addAssign("theform$id", "innerHTML", $sOut);  
    
    return $objResponse->getXML();
}

$objAjax = new xajax();

$objAjax->registerFunction('processForm');

$objAjax->processRequests();

$objAjax->printJavascript(); 

 

This is the onsubmit for the form

 

onsubmit="xajax_processForm(xajax.getFormValues('myform<?=$quote_id?>'),<?=$quote_id?>); return false;"

 

The code works great if I turn off mod_rewrite...I think I need to somehow set a base url, but I'm not sure  how to do it.  I've already got

 

<base href="http://www.mysite.com/" />

 

I had to do that to get my images and stuff to load after activating mod_rewrite.  But it doesn't seem to help the ajax calls.  Thanks for looking

 

Link to comment
Share on other sites

I just found this on codeignitor.

 

If you are using MOD_REWRITE, add the xajax_js in your .htaccess rule to look something like this:

##############################################

#RewriteEngine on

#RewriteBase /

#RewriteCond $1 !^(index\.php|img|css|public|tmp|download|javascript|rte|document|xajax_js|robots\.txt)

#RewriteRule ^(.*)$ /index.php/$1 [L]

 

 

I think I might be on to something.  I'm still not getting it to work though.

Link to comment
Share on other sites

Ya, I read the tutorial, but I don't understand how making my "virtual" URL more complicated will unconfuse my xajax.  I have already rewritten it to display as www.mysite.com/game/title and my rule has been working just fine...it's just the xajax functions aren't getting registered or something.  I think it's the extra "directory" that is throwing off the xajax functions.  I don't know enough about how it all works to know for sure.

Link to comment
Share on other sites

I figured it out.  Xajax's  printJavascript() function was getting lost because of the /game/title  to fix it I just added  printJavascript ($sJsURI="../")  The "../" puts it back in the root directory where the files actually are.  Works like a charm.  Thanks for your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.