andyrue Posted December 15, 2007 Share Posted December 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 post your code - would have to look at it Quote Link to comment Share on other sites More sharing options...
andyrue Posted December 15, 2007 Author Share Posted December 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 16, 2007 Share Posted December 16, 2007 Your going to have to use a "RewriteRule" in your htaccess file. I see you tried to do that above; but here is a article explaining how to do this: http://www.sitepoint.com/article/guide-url-rewriting/2 Quote Link to comment Share on other sites More sharing options...
andyrue Posted December 16, 2007 Author Share Posted December 16, 2007 is my ReWriteBase Directive bad? I'm not sure what I need to have my rule do...I need to know why it's having a problem before I can write anything to fix it. Quote Link to comment Share on other sites More sharing options...
andyrue Posted December 16, 2007 Author Share Posted December 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 16, 2007 Share Posted December 16, 2007 did you check out the tutorial I posted above: http://www.phpfreaks.com/forums/index.php/topic,172187.msg763561.html#msg763561 I think it will show you how to do this; so that you can rewrite your url to something like this: game/yada_yada/title/1 Quote Link to comment Share on other sites More sharing options...
andyrue Posted December 16, 2007 Author Share Posted December 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
andyrue Posted December 16, 2007 Author Share Posted December 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 16, 2007 Share Posted December 16, 2007 nice work 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.