Where to place a JQuery file? [SOLVED] |
[eluser]Frychiko[/eluser]
Hi, I've got jquery up and working but now I'm trying to test out some simple ajax/php: Code: $("tr.map_category").click(function() { The problem is... where do I place ajax_map_category.php? It would be nice if I could place all my ajax files into the ajax folder below: Code: codeigniter/
[eluser]richthegeek[/eluser]
jQuery + CI works quite well, but you need to be aware of a few things.. Because of CI's URL routing system (eg index.php/welcome/test) the browser will look for "ajax_map_category.php" at "index.php/wecome/test/ajax_map_category.php" To negate this you need to either use a root symbol (eg "/ajax_map_category.php" and put it in the root folder of your site), or add a javascript global variable which contains the base_url() output.
[eluser]Frychiko[/eluser]
Thanks for that advice, though it doesn't seem to have any effect :c ajax_map_category.php * located at the root of localhost/ci2/ Code: <?=header("Content-type: text/xml")?> jquery part Code: $.ajax({ id returns nothing and I don't think the php file is even being called..
[eluser]richthegeek[/eluser]
the root will go for localhost/ajax_map_category.php try using a line like this: Code: [removed] then prepend all ajax urls with Code: base_url +
[eluser]Frychiko[/eluser]
ok, I passed base_url() as a parameter to my jquery function. base_url() = http://localhost/ci2/ Code: var base_url = variables[2]; Not working either.. :o This all works fine outside of CI (porting a website over to CI)
[eluser]richthegeek[/eluser]
try alert'ing the script variable, make sure it is pointing to the correct place. Finally, try getting the results of that page just as text - it might be a content-type error that is stopping jQ from parsing the result as XML
[eluser]Frychiko[/eluser]
script variable outputs: Code: http://localhost/ci2/ajax_map_category.php xml object returns source code of current page (wrong) The content type is right.. I checked some previous ajax files from past projects. I wrote to a log file in the php file, but there's no log file.. so I don't even think the file is being called.. Code: <?=header("Content-type: text/xml")?>
[eluser]SpooF[/eluser]
Your best bet is to call the exact URL structure your passing in your script directly in your browser. See if the page even exists. If your using any .htaccess to remove the index.php you will need to make an exception for that file other wise its calling Quote:http://localhost/ci2/index.php/ajax_map_category.php
[eluser]Frychiko[/eluser]
Oh, file definitely exists in the URL. Anyway found the solution in my sleep last night. the URL word in the parameter list was being capitalized.. should have been all lowercase. Solved! |
Welcome Guest, Not a member yet? Register Sign In |