- Sep 29, 2004
- 18,665
- 67
- 91
I have a problem using this. It just seems to not work.
I am using AJAX (YUI2 API for it) to talk to the server. The server runs a PHP script.
In PHP, I essentially do this:
So, I have verified through FireBug that I am getting this string from responseText when running my javascript code:
Then I do this expecting to get the javascript array tempArrayObject['101'] = 'ABC':
the call to JSON.parse() seems to not be working. I have spent two hours on this and I am at a total loss. Pretty close to trying to use the YUI2 provided solution even though their comments say that if JSON.parse is available that their code simply calls it. Probably a good idea for legacy support but the current problem still is something I want to understand.
I am using AJAX (YUI2 API for it) to talk to the server. The server runs a PHP script.
In PHP, I essentially do this:
Code:
header('Content-type: application/json'); // needed so JSON.parse() in javascript knows how to handle the response
echo "{\"101\": \"ABC\"}";
So, I have verified through FireBug that I am getting this string from responseText when running my javascript code:
Code:
{"101": "ABC"}
Then I do this expecting to get the javascript array tempArrayObject['101'] = 'ABC':
Code:
<script>
// some code
var tempArrayObject = new Array();
var jsonParse = JSON.parse(o.responseText); // responseText is the string in the previous code block
tempArrayObject.push(jsonParse);
var selection = document.getElementById("someCmbobox");
for(var index in tempArrayObject) {
selection.options[selection.options.length] =
new Option(tempArrayObject[index], index, false, true);
}
// some code
</script>
the call to JSON.parse() seems to not be working. I have spent two hours on this and I am at a total loss. Pretty close to trying to use the YUI2 provided solution even though their comments say that if JSON.parse is available that their code simply calls it. Probably a good idea for legacy support but the current problem still is something I want to understand.
Last edited: