help with simple ajax |
[eluser]Unknown[/eluser]
Hi there, I'm new to ajax and don't know the first thing about it, but I need to use it on my site. I watched this tutorial on Nettuts+ and got a lot from it, but it still isn't enough for me to get ajax, since in my case, it doesn't work. The main functionality of my site is recording that a person attended a lecture. I display this data in a view and the data is displayed in a table from which I want to get the person id, and the lecture id. If I click on a link inside a tablecell which represents the arrival of a person X on a lecture Y, I want AJAX to register that in the database. If I do this manually (using phpmyadmin) it works great, but I need AJAX. I have a model called administration which has two functions. One of them (get_arrivals) is for retrieving data from a table which works great, but the other one, related to AJAX is causing me problems. Code: <?php The controller I use is called arrivals Code: <?php My jQuery function to get the person_id and lecture_id is this Code: $(function() The problem is when I run this in the browser, and click on a link inside a tablecell nothing happens (no database action, no AJAX action). I know I'm doing something wrong but I can't figure out what. Please give me a hand with this.
[eluser]smilie[/eluser]
Hm... in your jQuery you query for success: ... but your function is not returning anything :S Try: Controller: Code: if ($this->input->post('person')) And in model: Code: function save_arrival($data) I would also recommend that you also catch errors in live script Cheers, Smilie
[eluser]CroNiX[/eluser]
I believe Code: data: { person: person_id, lecture: lecture_id, arived: yes}, Code: data: { person: student_id, lecture: lecture_id, arived: "yes"}, You never defined a "person_id", but you did define "student_id" but you never used it. "yes" is a string and should be in quotes. Nothing to do with the functionality of the code, but "arived" is spelled "arrived". Also, where is "window_location" that you are using for the ajax call defined in your javascript? |
Welcome Guest, Not a member yet? Register Sign In |