Welcome Guest, Not a member yet? Register   Sign In
Passing JSON data to the server (?)
#1

[eluser]taewoo[/eluser]
Hi everyone.
Is there a way to pass the JSON data object from client to server w/o enumerating thru the data (list)? (Since my controller expects a certain # of arguments)... not open ended list of arguments.
#2

[eluser]TheFuzzy0ne[/eluser]
To my knowledge, that's not something that CodeIgniter supports at the current time.

Is there any reason why it must be JSON that you pass back to the server?
#3

[eluser]taewoo[/eluser]
ok.. well, there is this JSON.toJSONString() at http://www.json.org/JSON.js. Except now I come across the issue of permitted URI characters...

The reason is because I am doing a widget that dynamically takes in javascript parameters (like Ad-Sense) and it is forwarded to my server via GET on iframe. There are values that might be multiple... since my controller expects certain # of arguments, i figured it'd be best to pass JSON object as GET parameter but apparently, that is not the smartest thing to do.

Is there another way that you recommend that I do this?
#4

[eluser]TheFuzzy0ne[/eluser]
If you send the data back using the POST method I don't believe you will be restricted.

As I don't know exactly what kind of data you are planning on sending to the server, it would be inappropriate for me to suggest a format for you're return data.
#5

[eluser]rvent[/eluser]
Code:
$dbQuery = $this->db->query("SELECT PartNumber, PartNumberID FROM PartNumber
                                    $where LIMIT $limit");
        
        $total =  $dbQuery->num_rows();
        $data = json_encode($dbQuery->result_array());
        $data = '{"total":"'. $total. '","results":' .$data. '}';
        $this->output->set_output($data);

It woks fine for all my CI and JavaScript stuff...
#6

[eluser]TheFuzzy0ne[/eluser]
I thought he wanted to send data from the client to the server, not the other way around?
#7

[eluser]rvent[/eluser]
[quote author="TheFuzzy0ne" date="1209670371"]I thought he wanted to send data from the client to the server, not the other way around?[/quote]

My bad Smile

I misunderstood the question...

I think someone mentioned before, but i guess you ll have to DIY with the data from the POST
#8

[eluser]megabyte[/eluser]
My question would be how are you taking in these Javascript parameters? And why not just take them into a hidden form field and then post them to the server?
#9

[eluser]nirbhab[/eluser]
buddy if you are taking about AJAX Request, to send a JSON request type, than its true, you can,
if you are taking about submitting something to server from client, i guess there are only 3 types
1. SESSION
2. POST
3. GET

In broader term sending any request to server for JSON or XML type is done in Ajax.
Refer any JS Framework like jquery or mootools, rather than doing it from scratch. :-)
#10

[eluser]Jay Turley[/eluser]
[quote author="taewoo" date="1209611814"]Hi everyone.
Is there a way to pass the JSON data object from client to server w/o enumerating thru the data (list)?[/quote]

If you have an existing JSON object, just use the XmlHttpResponse object to pass it to a controller as a POST request. As others have mentioned, using a framework like jQuery is a huge help, instead of writing it from scratch.

If you don't have the existing JSON data object, then you will have to create it before posting it, but fortunately JSON is just a javascript array (essentially) and is very easy to create.




Theme © iAndrew 2016 - Forum software by © MyBB