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
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTML as JSON attribute via AJAX

    Hey all, first post.

    I'm trying to using ajax to fetch a JSON object via PHP. When I construct the object in the PHP script I create an attribute called "content", and in that attribute is some html... only of course when I try to parse the JSON response on the client side, I get syntax errors.

    I've stripped out all \n and \r characters and used addslashes() to escape the quotes, yet still get syntax errors. What am I missing?

    Or alternatively, is there a better way to return presentation content through ajax and parse it into html on the client side?

    Remarkably, google is not my friend in this instance... any help much appreciated.


    Dave.

    EDIT: whoops, looks like I might have posted this in the wrong section. Any mod feel free to move if appropriate.
    Last edited by dangerdaveCS; 03-13-2009 at 07:59 PM.

  • #2
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, so I've partially solved it. A rather wierd result.

    Firstly, I found that single quotes weren't being handled properly. After trying for ages myself I figured instead of using str_replace etc, I could use json_encode PHP functions. That solved the single quote problem.

    Now onto a weird problem indeed. For some reason all my HTML is fine now, *except* for the tag <form>, which causes a parse error. It could just be the json javascript library I'm using has some bug, but I don't know. Strange, just that one tag that causes a parse error and no others.


  •  

    Posting Permissions

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