Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2009, 07:56 PM   PM User | #1
dangerdaveCS
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dangerdaveCS is an unknown quantity at this point
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..
dangerdaveCS is offline   Reply With Quote
Old 03-13-2009, 08:45 PM   PM User | #2
dangerdaveCS
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dangerdaveCS is an unknown quantity at this point
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.
dangerdaveCS is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:30 AM.


Advertisement
Log in to turn off these ads.