Welcome Guest, Not a member yet? Register   Sign In
AJAX / Javascript and form submission url (quick question)
#1

[eluser]Unknown[/eluser]
Just a quick question. I looked for an answer but couldn't find anything but I'm sure there is an easy answer for all experienced CodeIgniter users

I used the following for an AJAX call:

Code:
objX.open('POST', '<?php print site_url('admin-category/add-category'); ?>', true);

Great, works fine... in the header.

When I moved it to its own JavaScript page I got an error so added the following to the htaccess file to make sure that PHP can be read on a JavaScript page:

Code:
AddType application/x-httpd-php .js
AddHandler x-httpd-php5 .js

<FilesMatch "\.(js|php)$">
SetHandler application/x-httpd-php
</FilesMatch>

Great, however the PHP error now reads that the the function site_url is unknown. Well of course it is because main-file.js is independent of the CodeIgniter PHP code base.

What is the quickest way of adding a javascript file like this so CodeIgniter PHP functions will work within it?




Theme © iAndrew 2016 - Forum software by © MyBB