Insert record via AJAX |
[eluser]agubski[/eluser]
Dear community, I have a difficulty to realize AJAX record insertion into a database. I'm calling a PHP file via following function Code: function ajaxFormPost1(){ and actual file looks like Code: <?php
[eluser]Krzemo[/eluser]
Am I missing somthing or there is nothing related to CodeIgniter here? Why is there POST in JS code Code: ajaxRequest.open("POST", "query/writecomments.php", true); Code: $myimage = $_GET['image']; What Firebug says? Are you really making a request? What is the server response? And why are you 'reinventing the wheel' with JS code? Use jQuery - JS part will be much more pleasant. If calling the PHP file via URL in browser doent insert data too, apparently there is something wrong with PHP code...
[eluser]agubski[/eluser]
Actually some of my comments were lost My question was if I can send AJAX request to a controller function rather that calling an external php file. please disregard Code: $myimage = $_GET['image']; Thanks Alex
[eluser]Krzemo[/eluser]
In proper CodeIgniter application you can make requests only to controller functions.
[eluser]agubski[/eluser]
So, will something like this work? CI controller function. (I know it works as I made calls to it from views and id does). Function is in the controller named "Welcome" Code: function insert() The JS on the other hand doesn't seem to do much. Code: rest of AJAX function same as above
[eluser]agubski[/eluser]
Sorry fro confusion if I wasn't clear enough. I'd like to pass variables from the form via AJAX call to controller function and save data into the database. I need proper way to write AJAX call to the above controller function. I'm not familiar with jQuery, but has written JS calls before which don't seem to work now for some reason Appreciate you being that patient so far
[eluser]Krzemo[/eluser]
I would insist on giving a jQuery a try. It has gr8 docs and making it run will take you 30mins max. If you have a form you are going to submit and you want to do it 'via ajax' jQuery plugin from here http://jquery.malsup.com/form/ |
Welcome Guest, Not a member yet? Register Sign In |