www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-02-2009, 05:46 AM
    fireblade's Avatar
    fireblade fireblade is offline
    burn for ever
     
    Join Date: May 2007
    Posts: 139
    php json_decode . Help please

    I have a varibale created in javascript as follows
    HTML Code:
    var jsonData = {"data1" : "dataContent"};
    when i pass this to server through ajax.. I am decoding
    PHP Code:
    $vars = json_decode($jsonData);
    But I am not getting the correct result when printing this

    PHP Code:
    print_r($vars);
    I am getting empty result.

    Is there any error in this?
    __________________
    <Javascript Smooth Scroller> | <Free Multi Transition Banner >

    Nothing builds self-esteem and self-confidence like accomplishment
    Reply With Quote
      #2  
    Old 11-02-2009, 01:57 PM
    mitya mitya is offline
    Registered User
     
    Join Date: Oct 2003
    Location: Nottingham
    Posts: 668
    Well where are you declaring $jsonData? I can't see that you are.

    Also, note that you don't need quotations around object property names, so the following two syntaxes will work the same:

    Code:
    var jsonData = {"data1" : "dataContent"};
    var jsonData = {data1 : "dataContent"};
    Reply With Quote
      #3  
    Old 11-02-2009, 06:16 PM
    rnd me's Avatar
    rnd me rnd me is offline
    working on the chain...
     
    Join Date: Jul 2008
    Location: urbana, il
    Posts: 1,275
    Quote:
    Originally Posted by mitya View Post
    01
    Also, note that you don't need quotations around object property names, so the following two syntaxes will work the same:

    Code:
    var jsonData = {"data1" : "dataContent"};
    var jsonData = {data1 : "dataContent"};
    Yes, you do need to quote JSON key names...

    PHP's json_decode would fail without them, and how else would you store reserved name properties?
    Reply With Quote
      #4  
    Old 11-02-2009, 06:40 PM
    rnd me's Avatar
    rnd me rnd me is offline
    working on the chain...
     
    Join Date: Jul 2008
    Location: urbana, il
    Posts: 1,275
    Quote:
    Originally Posted by mitya View Post
    Also, note that you don't need quotations around object property names, so the following two syntaxes will work the same:

    Code:
    var jsonData = {"data1" : "dataContent"};
    var jsonData = {data1 : "dataContent"};
    Yes, you do need to quote JSON key names...

    How else would you store a property named constructor?
    Reply With Quote
      #5  
    Old 11-03-2009, 03:26 AM
    fireblade's Avatar
    fireblade fireblade is offline
    burn for ever
     
    Join Date: May 2007
    Posts: 139
    Yes,

    I have quoted as follows..

    Code:
    var jsonData = {"data1" : "dataContent"};
    I pass this to PHP through ajax and i get the variable to a php function as a post variable. and I start processing it.

    before submitting I can test this in javascript like

    Code:
    alert(jsonData.data1);
    it works fine. and am getting result "dataContent"

    in the server result like below
    PHP Code:
        public function deleteUsers($jsonData)
        {
            echo
    $jsonData; // this will print "[object Object]"
            
    $vars = json_decode($jsonData);
            
    print_r($vars); // nothing will be printed
        
    }
    this is ma problem
    __________________
    <Javascript Smooth Scroller> | <Free Multi Transition Banner >

    Nothing builds self-esteem and self-confidence like accomplishment
    Reply With Quote
      #6  
    Old 11-03-2009, 02:07 PM
    rnd me's Avatar
    rnd me rnd me is offline
    working on the chain...
     
    Join Date: Jul 2008
    Location: urbana, il
    Posts: 1,275
    you're not running JSON.stringify() before you upload the javascript are you?
    Reply With Quote
      #7  
    Old 11-04-2009, 01:13 AM
    fireblade's Avatar
    fireblade fireblade is offline
    burn for ever
     
    Join Date: May 2007
    Posts: 139
    WWOW...

    2 thumbs.. This is what i wanted. Thanks my friend. It worked for me.
    __________________
    <Javascript Smooth Scroller> | <Free Multi Transition Banner >

    Nothing builds self-esteem and self-confidence like accomplishment
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:37 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.