When I use JSON data obtained by:
$.getJSON("http://192.168.1.9:8983/solr/db/select/?wt=json&&start=0&rows=100&q="+elegant+"&hl=true&hl.fl=description&hl.usePhraseHighlighter=true&json.wrf=?", function(newresult)开发者_运维百科{
and use this JSON data as:
$.each(newresult.highlighting, function(i, hitem){
alert(hitem.description[0]);
});
then I am not getting the description field value.
But when I assign whole data in a variable, say newresult
and then run $.each()
it is working, as I did in http://jsfiddle.net/taL8x/1/. Please tell me what is the problem when I use data through getJSON()
.
If passing line at alert
, newresult.highlighting should be object or array. then, this is not a problem about Same Origin Policy. And you are specifying json.wrf=?
for callback.
Probably, you missed about struct of element in highlighting array. maybe.
Try to access directry, and confirm structure of the array.
You are expecting:
{
"highlighting": [ { "description" : "foo" }, { "description" : "bar" } ]
}
But it may be
{
"highlighting": { "A001" : { "description" : "foo" }, "A002" : { "description" : "bar" } }
}
Your request is probably stopped by the Same Origin Policy. If the service is on a different URL, you will have to use JSONP.
精彩评论