Ali Asif
Ali Asif

Reputation: 37

IS There any way to send values from JavaScript to Controller in CodeIgniter?

OnClick Event of a button the values enter by user inside Username and Password text boxes are successfully retrieved into the javaScript function, now I want to send these values to CodeIgniter controller is there any way to do it??? thanks in Advance :)

Upvotes: 1

Views: 1576

Answers (2)

Anonymous
Anonymous

Reputation: 1979

Here is how I do it with jquery...pretty simple.

url: "<?php echo base_url('index.php/site/addItems/'); ?>",

is pointing to a function in the controller

    $('#addItem').click(function(){
    var id = $('#id').val();
    var data = {
        item: $('#itemName').val(),
        price: $('#itemPrice').val(),
        id: $('#id').val()
    };
    $.ajax({
        url: "<?php echo base_url('index.php/site/addItems/'); ?>",
        type: "post",
        data: data,
        success: function(msg) {
            $('#items').html(msg);

        }
    });

Upvotes: 1

Related Questions