Can't see JSON data
Even though I can get a JSON file that gets downloaded, when I go to my remote URL. When I use the following code in my javascript, nothing happens:
<input type="text" id="query" /><button>search</button><br />
<div id="results">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//var url='http://search.twitter.com/search.json?callback=?&q=google+wave';
var url = url + '/Services/GetNthClosestDriverLocationToMe?callback=?&latitude=30&longitude=-97.6&nth=2';
var query;
$('button').click(function(){
query=$("#query").val();
$.getJSON(url+query,function(json){
$.each(json.results,function(i,tweet){
//$("#results").append('<p><img src="'+tweet.profile_image_url+'" widt="48" height="48" />'+tweet.text+'</p>');
$("#results").append('<p>'+tweet.Name+'</p>');
});
});
});
});
</script>
Notice the commented out twitter URL that works just fine. This makes me think that it has something to do with my URL, even though I am able to get the JSON file when i simply go to the url from the browser. Also, note that my UR开发者_JAVA技巧L is on a remote domain.
Your url
var is undefined in your code. This might be the problem.
If not, please put your full code. Your url might be malformed.
Thanks for all the replies. After firing up fire-bug, the problem is not in the code, but in my JSON (posted in one of my replies above). Unlike the Twitter result, mine is not a collection, and thus it was erroring out on $.each.
精彩评论