Welcome Guest, Not a member yet? Register   Sign In
Prototype Ajax w/ CI Help
#1

[eluser]jaystang[/eluser]
Hey guys,
I'm a bit new to CI and I've been playing around with trying to make an Ajax call to my controller passing a JSON object. Below is the code I've got so far...

Javascript Code:
Code:
var categoryParams = {'categoryId': 123456, 'applicationId': 789123};
var categoryParamsJson = Object.toJSON(categoryParams);

var params = 'params=' . categoryParamsJson;

new Ajax.Request(baseUrl + 'index.php/applications/Applications/testajax/',
{
    method:'post',
    contentType: 'text/json',
    parameters: params,
      onSuccess: function(response)
    {
        alert(response.responseText);
    },
    onFailure: function(){ Alert('failed') }
});

PHP Code:
Code:
public function testajax()
{
    $this->load->helper('json');
    
    $decodedData = json_decode($this->input->post('params'));
    
    echo('hello world from server!' . $decodedData->categoryId);
    die;
}

My issue is with passing an object. Everything works fine if I only pass one integer rather then the object. Any thoughts what I'm doing wrong here?

Thanks.


Messages In This Thread
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 09:23 AM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 12:28 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 01:23 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 02:05 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 03:49 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 04:19 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 05:43 PM
Prototype Ajax w/ CI Help - by El Forum - 03-12-2010, 07:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB