I am using the jQuery ajax method to get data from the database and return the data via a json object. However one of the values in this json object is an HTML string. I am basically doing exactly what is seen here except I need to know how I can remove the slashes that jQuery is adding to the HTML string. Any ideas?
Example
json.HTML = Click <a href=\"http://example.com/example.php\">here</a>;
//Needs to be
json.HTML = Click <a href="http://example.com/example.php">here</a>;
I was hoping to do this without code if possible.
UPDATE
Ok I found that if I do htmlentites before it is returned, then the slashes are not there when the value comes in. Now, which jquery function would I use to insert this string inside a td element without slashes being added by .html or .text functions.
Here is what it looks like directly from the json.HTML value,
Click <a href=\"http://example.com\">here</a>
And here is after it is displayed using .html
Click <a href=\"http://example.com\">here</a>
And here is after is it displayed using .text
Click <a href=\"http://example.com\">here</a>
I wonder if I need to use .val maybe? Oh one more thing, I want this HTML to be display literally, not the actual HTML to be inserted into the code.
Could it be as simple as:
stringvar.replace('\\','');
I don't think your problem is jquery adding slashes. I don't think your returning the json properly form your php are you using json_encode and giving json header ? what does the json result look like if you save it as a text file ?
also if you can't get it to come down properly you can use
unescape function
out put this as your json
$foo = 'Click <a href="http://example.com">here</a>';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
echo json_encode($foo);
and see if does the same thing
EDIT dont use text you want something like
$('#table_id td').html(json_response);
that is pseudo code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With