Jump to content
php.lv forumi

Json Php Jquery - datu apmaiņa


Recommended Posts

Posted

<?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'

Posted

Šā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?

Posted (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 by codez
Posted

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){});

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...