getJSON in CI problem |
[eluser]Mitja B.[/eluser]
Code: $izb = $_GET['izb']; Code: /* getJSON */ how can i import this in CI. I have no idea how tu use getJSON in CI.
[eluser]Mitja B.[/eluser]
i look this link http://codeigniter.com/wiki/JSON_Helper/ but not helping me
[eluser]Crimp[/eluser]
The $GET global is destroyed in CI. Use the higher level $.ajax function in jQuery with $POST and set the datatype to JSON. Also, the PHP json_encode function requires a newer version, 5.2. You can check if the function exists and parse "manually" if it doesn't.
[eluser]Mitja B.[/eluser]
do you have maybe any example of how to make all this? regards
[eluser]Mitja[/eluser]
I also trying with getJSON in CI. I try jquery getJson http://docs.jquery.com/Ajax/jQuery.getJS...tacallback but nothing works. Can someone tell em how can i use getJson in CI?
[eluser]narkaT[/eluser]
the first thing you should do, is cleanup your php-code the switch/case-statement is totally useless, you could just drop it. every variable you plan to use (especially if it is an array) should be declared first, to prevent unexpected data to be injected into your application. in combination with register_globals such "errors" would allow "evil-people" to run xss-attacks. concerning the JS I would use jquery's post-funktion. there is also a exmaple for a simple wrapper functionin the documentation: Code: $.postJSON = function(url, data, callback) { and remeber to change $_GET to $_POST Greetings Jan
[eluser]Mitja[/eluser]
narkaT thx you. Do you maybe have any example of it. How to auto-populating Select Boxes in CI.
[eluser]narkaT[/eluser]
there's nothing special about implementing such a functionality with CI. Just create a controller that handles the data fetching: Code: class Fetchselectboxes extends Controller { you could then access the data with the following url: Code: www.yourdomain.com/fetchselectboxes/fetchjson/<id> the most work will be done on the client-side, so the server-side implementation is quite simple Greetings Jan
[eluser]Mitja B.[/eluser]
How to call fetchjson function in first <select> that will work on second <select>. Like onChange="www.yourdomain.com/fetchselectboxes/fetchjson/<id>" or somehowe else. Before i use JS function /* getJSON */ function spremeniVrednost() { $.getJSON("ajax.php", { izb: $("#select1").val()}, function(json){ $("#select2").removeOption(/./); $("#select2").addOption(json); } ); } <select name="select1" id="select1" style="width: 250px;"> I make fnction like you said and use echo json_encode($data); but do not know what next |
Welcome Guest, Not a member yet? Register Sign In |