Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Echo a JSON

  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    45
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Echo a JSON

    Goal: Send data to the server and then the server return a JSON containing new data.

    What I got:

    Code:
    //JS PART
    $.post("welcome.php", 
    	{ 
    	x: 345, 
    	y: 456	
    	})
    		.done(function(data){
    		
    		var obj = eval(data);
    		
    		console.log(obj.first); //Would like to return 345
    		
    });	
    
    //Welcome.php
    $x=$_POST["x"];
    $y=$_POST["y"];
    
    $data = array(
            'first' => $x,
            'second' => $y,
        );
    
    
    $json = json_encode($data);
    echo $json;
    Last edited by IdkWhatsRc; 06-15-2013 at 03:05 AM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Code:
    document.getElementById('someElement').innerHTML=obj.first;
    ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    May 2013
    Posts
    45
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages View Post
    Code:
    document.getElementById('someElement').innerHTML=obj.first;
    ?
    Not woking. I don't reall see why innerHtml would work if console.log doesn't.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •