I am trying to use the getJSON function in jQuery to import some data and trigger a callback function. The callback function doesn\'t run. However, if I try the same thing w
As mentioned by numerous others, you need valid JSON (i.e. complies with the rules at http://json.org/) for getJSON
to work (this means you cannot get HTML via getJSON
as in your example).
The reason the last test works is because the last parameter "json" is not being interpreted as the "type". Because the following does NOT work:
$("#test3").click(function() {
$.get("index.html",
'',
function(response) {
alert('hi');
//works
},
"json"
)
});