Welcome Guest, Not a member yet? Register   Sign In
Simple explanation needed on jquery
#1

[eluser]bhakti.thakkar[/eluser]
HI all,
I am new to jquery. I am implementing it in my CI application. I have downloaded the latest jQuery JavaScript Library v1.3.2. I got a simple example on the internet and i think of starting with the same. Below is the code in the view page


Code:
[removed]
$(document).ready(function() {
    $('#submit').click(function() {

        var msg = $('#message').val();
        alert(msg);
        $.post("<?=site_url('certificates/AJAXUpdateDB') ?>", {message: msg}, function() {
            $('#message').val('');
        });
    });
});
[removed]

I need to know two things of the bold line:
in the line site_url('message/add') -- i learn that message is a controller and add is a function in it that will execute lines of code. But i dont get the text i.e {message: msg}. if in this case it is the control name(id to be specific) and msg is the value, then how will i pass radio button?
and the second doubt is whether i should use site_url or base_url?

Controller
certificates.php

Code:
function AJAXUpdateDB() {
        print "here";
        $msg = $_POST['message'];

        $stmt="update TransactionCertificate_T set InvoiceReference_VC = '$msg' where TransactionCertificate_ID = '$TransactionCertificate_ID'";
        $this->db->query($stmt);
        return;
    
    }

when i call this, nothing happens.
Where am i wrong
#2

[eluser]vitoco[/eluser]
Code:
function AJAXUpdateDB() {
        print "here";
        $msg = $_POST['message'];
        $stmt="update TransactionCertificate_T set InvoiceReference_VC = '$msg' where TransactionCertificate_ID = '$TransactionCertificate_ID'";
        $this->db->query($stmt);
        return;
    
    }
first, the variable $TransactionCertificate_ID in the query doesn't exists, so the query can update cause the WHERE is invalid.
second, change the $_POST['message'] to $this->input->post('message');
third, $msg as input, must be sanitize, in order to avoid SQL injection.

Saludos
#3

[eluser]_kailash[/eluser]
If you have to submit forms with Jquery you can use the Jquery form plugin, that will solve your radio button problem.
I think you should use site_url() as it is easier, hower you should check them out on the CI documentation
#4

[eluser]cahva[/eluser]
Like vitoco said, you are missing the actual ID. If $TransactionCertificate_ID is coming from the form, its $this->input->post('TransactionCertificate_ID');

To sanitize, use active record which will handle that for you:

Code:
$this->db->set('InvoiceReference_VC',$this->input->post('message'))
        ->where('TransactionCertificate_ID',$this->input->post('TransactionCertificate_ID'))
        ->update('TransactionCertificate_T');




Theme © iAndrew 2016 - Forum software by © MyBB