Jump to content

JSON.parse() return string with no double quotes?


tinfanide
 Share

Recommended Posts

I have a websitehttp://lifelearning.x10.mx/test/t.htmlwhich returns a string from a server text file loaded by AJAX.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script src="json2.js"></script><script src="php_slides.js"></script><script>window.onload = function(){ajax(function(){  document.getElementById("SlideLink").innerHTML = sJSON;  },"GET","php_slides.txt",true);}</script></head><body><textarea id="SlideLink"></textarea></body></html>// php_slides.jsvar sJSON, xmlhttp;var ajax = function(action,method,source,async){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){  if (this.readyState == 4 && this.status == 200)  {   sJSON = JSON.parse(this.responseText);     action();  }};xmlhttp.open(method,source,async);xmlhttp.send(null);}

The text file:http://lifelearning.x10.mx/test/php_slides.txt

"This is a quote."
The returned string is the one with the double quotes removed.How could I have the string completely returned by AJAX?
Link to comment
Share on other sites

The content of your text file isn't JSON, so you shouldn't use JSON.parse(). Just use the returned string as it is.
Yes, a careless mistake. Overlooked it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...