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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts

    passing variable between PHP and javascript

    Dear all,

    I face problem with passing value between PHP and Javacript.

    for example:
    in PHP, i encode the value with "urlencode" function and pass to javascript.

    but when i decode with javascript "decodeURIComponent" or decodeURI" function may not all the string will return to original.

    *string = "A B C"; ->encode with php function
    in javascript show A+B+C -> i assign to a text box/ alert out.

    i found out that JSON class can be solve my problem but problem was the system is not developed by me since started. This was quite difficult for me to integrated the JSON with my system.

    isn't have list that show out the string the encode by PHP function may not able to decode by javascript?

    Pls help. Thanks a lot.
    Last edited by CstAn; 02-28-2007 at 04:50 PM.

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Location
    Utah
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To be honest, I have no idea what it is you are trying to do.

    You mentioned JSON so I assume you are using some variation of the AJAX paradigm. Remember that output from PHP is converted to a format that can be transferred with HTTP. This is generally HTML or plain-text but it can be JavaScript, CSS, PDF, etc..

    JavaScript can read anything you pass through its internal "HttpRequest" object. (if the browser has one). You don't have to encode or decode text unless the format requires it. You can simply send a text string or XML or JSON or HTML.

    You can also write javascript with PHP and then have your page either statically or dynamically load that file as a script src tag. Just make the file x.php and change the Content-type to text/javascript.


  •  

    Posting Permissions

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