• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send array in jquery to controller?

#1
[eluser]shinokada[/eluser]
I am learning ajax with jquery and CI.

I am not doing right with the following jquery code and a controll function.

I think I am not doing right with this line.

$.getJSON(
'phpjquerybook/inline_editing_do',
{'id':id,'field_name':field_name,'value':this.value},


or
function inline_editing_do($id=null){
$id=(int)$id['id'];
$field_name = addslashes($id['field_name']);
$value= addslashes($id['value']);

I think I am not sending/receiving array correctly.

Any help will be appreciated it.

Thanks.


Jquery code.

Code:
...
...
function inline_editing_save(){
    var id,field_name,p;
    p=this[removed];
    if(p.originalHTML==this.value)
        return inline_editing_restore(p);
    field_name=p.className;
    id=$(this).closest('tr')[0].id.replace(/.*_/,'');
    $.getJSON(
        'phpjquerybook/inline_editing_do',
        {'id':id,'field_name':field_name,'value':this.value},
        inline_editing_callback
    );
}
...
...

Controller

Code:
function inline_editing_do($id=null){
        
        // $id=(int)@$_REQUEST['id'];
        // $field_name=addslashes(@$_REQUEST['field_name']);
        // $value=addslashes(@$_REQUEST['value']);
        $id=(int)$id['id'];
        $field_name = addslashes($id['field_name']);
        $value= addslashes($id['value']);
        echo ( !($id%2) )?
            "{'id':$id,'field_name':'$field_name','success':1,'value':'$value'}":
            "{'id':$id,'field_name':'$field_name','success':0,'error':'Could not save data'}";
        
    }

#2
[eluser]T I[/eluser]
<?=site_url('phpjquerybook/inline_editing_do')?>

load the url helper in Controller.

#3
[eluser]shinokada[/eluser]
Thanks Md. But it does not work.

any more help?

#4
[eluser]T I[/eluser]
It shd work. Smile
Code:
$('#submit').click(function() {

        var jname = $('#name').val();
        var jprincipal = $('#principal').val();
        var jpayment = $('#monthly_payment').val();
        var jrate = $('#interest_rate').val();

        $.getJSON("<?= site_url('debt_sw/save') ?>", {debt_name: jname,principal:jprincipal,monthly:jpayment,interest_rate:jrate}, function(data) {

          if(data)
              {
                   $("#update").html(data);
                 $("tr:even").css("background-color", "#7FDDF6");
                 $("tr:odd").css("background-color", "#ECECEC");

              }

        });
    });
});


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.