getjson

jQuery getJSON works locally, but not cross domain

删除回忆录丶 提交于 2019-11-26 04:27:10
问题 I\'ve searched FOREVER and can\'t come up with a definitive answer to my problem. So here it is. I have a JSON file (I went to jsonlint to validate and it says its good) that looks like this (some information modified): [{ \"position\":\"1\", \"category\":\"A\", \"title\":\"Title to first story\", \"description\":\"The first story.\" }, { \"position\":\"2\", \"category\":\"B\", \"title\":\"Title to second story\", \"description\":\"The second story\" }, { \"position\":\"3\", \"category\":\"B\

load json into variable

一笑奈何 提交于 2019-11-26 02:42:16
问题 I have to do something very simple, but there doesn\'t seem to be an easy way to do this, as far as I can tell. I just want to load JSON data from a remote source and store it in a global Javascript variable using jQuery. Here\'s what I have: var my_json; $.getJSON(my_url, function(json) { var my_json = json; }); The my_json variable remains undefined. I think this is clearly a scope issue. It seems to me the $.getJSON method should return JSON, but it returns an XMLHttpRequest object. If I

Is it possible to set async:false to $.getJSON call

我们两清 提交于 2019-11-26 01:59:14
问题 Is it possible to set async: false when calling $.getJSON() so that the call blocks rather than being asynchronous? 回答1: You need to make the call using $.ajax() to it synchronously, like this: $.ajax({ url: myUrl, dataType: 'json', async: false, data: myData, success: function(data) { //stuff //... } }); This would match currently using $.getJSON() like this: $.getJSON(myUrl, myData, function(data) { //stuff //... }); 回答2: Both answers are wrong. You can. You need to call $.ajaxSetup({ async

Passing JSON data to .getJSON in jQuery?

亡梦爱人 提交于 2019-11-25 15:18:24
I am trying to pass a JSON object to .getJSON but I keep getting a bad request error. This is what I am trying: var data = { "SomeID": "18", "Utc": null, "Flags": "324" }; $.getJSON("https://somewhere.com/AllGet?callback=?", JSON.stringify(data), function (result) { alert(result); }); Currently to get it working, I have to do this, but I do not like how I have to manually construct the query string: $.getJSON("https://somewhere.com/AllGet?SomeID=18&Utc=&Flags=324&callback=?", null, function (result) { alert(result); }); Anyone know how to make requests easier with JSON objects being passed in?