Wuu Posted March 31, 2010 Report Posted March 31, 2010 <?php $res = json_decode($_REQUEST['data'], true); $send = array ('data'=>'i am php','say'=>$res); echo json_encode($send); ?> function send(data) { $.getJSON('jCore.php', { data: "i am json" }, function(json){ alert('php say: ' + json.data + ' ' + json.say); }); } Nespēju ar php nolasīti 'i am json' datus un nosūtīti tos atpakaļ, kur kodā kļūda? Visu laiku atbilde 'null' Quote
codez Posted March 31, 2010 Report Posted March 31, 2010 debugo pa soļiem, sāc ar to vai requestā ir dati, tad vai pēc json_decode ir pareizi dati, utt. Quote
2easy Posted March 31, 2010 Report Posted March 31, 2010 varbūt izņem data no funkcijas argumenta? Quote
codez Posted March 31, 2010 Report Posted March 31, 2010 $res ir tukšs nu tad mēģini $_GET['data']; Quote
Wuu Posted March 31, 2010 Author Report Posted March 31, 2010 Šādi strādā! $send = array ('data'=>'i am php','say'=>$_REQUEST['data']); Tad kāda velna pēc ir vajadzīgs $res = json_decode($_REQUEST['data'], true); ? Kurš neatgriež neko? Vai arī mans manuālis ir fake and gay? Quote
codez Posted March 31, 2010 Report Posted March 31, 2010 (edited) Principā šijā gadījumā tu jau to json_decode taisi stringam, kam normālā gadījumā vajadzētu atgriezt to pašu stringu. man: $res = json_decode('i am json', true); echo $res; //i am json Edited March 31, 2010 by codez Quote
Wuu Posted March 31, 2010 Author Report Posted March 31, 2010 Tad sanāk, ka es varu arī iztikti bez json_decode? Quote
codez Posted March 31, 2010 Report Posted March 31, 2010 ja sūti vienkāršu stringus tad, jā. json_decode būtu vajadzīgs, ja tu sūtītu json datus, piemēram: $.getJSON('urlis',{data:{a:1,b:2}},function(d){}); Quote
Wuu Posted March 31, 2010 Author Report Posted March 31, 2010 Liels paldies! p.s. codez tev 1000 posti :D Quote
codez Posted March 31, 2010 Report Posted March 31, 2010 dažreiz iemetu acis:Top psters 2easy vienmēr ir 1. vietā. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.