getjson

How to use native javascript write jquery $.getJSON function?

主宰稳场 提交于 2019-12-04 16:06:07
A demo i only want to use jquery $.getJSON function,but now i must import jquery, so i want to use native javascript write jquery $.getJSON function. My Code is: var $={ getJSON: function(url, params, callback){ var reqUrl = url; var xhr = new XMLHttpRequest; xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { JSON.parse(xhr.responseText); } } xhr.open("GET", reqUrl); xhr.send(); } }; use chrome show: XMLHttpRequest cannot load xxxx Origin xx is not allowed by Access-Control-Allow-Origin. who can help me? Make an ajax request and use JSON.parse on the result.

理解js异步编程

别说谁变了你拦得住时间么 提交于 2019-12-04 13:40:03
Promise 背景 javascript语言的一大特点就是 单线程 ,在某个特定的时刻只有特定的代码能够被执行,并阻塞其它的代码,也就是说,同一个时间只能做一件事。 怎么做到异步编程?回调函数。直到nodejs的出现,开始将回调模式的异步编程机制发挥的淋漓尽致,这种机制开始在前端变得非常流行,但是慢慢也体现出了回调函数在 错误处理 和 嵌套 上的副作用。 因为存在上面的不足,所以异步解决方案一直在发展中,从 callback => promise => generator => async/await => rx => ..... 简单了解event loop +javascript上, 所有同步任务都在主线程上执行,也可以理解为存在一个“ 执行栈 ”。 主线程外,还有一个“ 任务队列 ”,任务队列的作用,就在等待异步任务的结果,只要异步任务有了运行结果,就会加入到“任务队列”中。 一旦 执行栈 中所有同步任务执行完毕,就从 任务队列 中读取“任务”加入到“执行栈”中。 主线程不断的在循环上面的步骤。 (function() { console.log('这是开始'); setTimeout(function cb() { console.log('这是来自第一个回调的消息'); setTimeout(function cb3() { console.log(

Send Json Array Through jQuery Ajax

…衆ロ難τιáo~ 提交于 2019-12-04 11:14:00
I am going to send a array of json object through jquery ajax call to a php file. var arr = new Array(); var record1 = {'a':'1','b':'2','c':'3'}; var record2 = {'d':'4','e':'5','f':'6'}; arr.push(record1); arr.push(record2); How can I send the array through jquery ajax? and how can I get the values in php? Thanks. $.ajax({ url: "api", type: "POST", dataType: 'json', data: JSON.stringify(arr), success: function(response){} }); And with PHP: $strRequest = file_get_contents('php://input'); $Request = json_decode($strRequest); I think JSON.stringify() might be useful. or, you can use json_decode()

How to get 406 Error (not acceptable) in jquery

只谈情不闲聊 提交于 2019-12-04 06:32:18
问题 I am doing error handling in my.js, where i am having cross domain call to other server, also for dynamic HTML template i am using Mustache.js. $.getJSON(url, function(data, textStatus, xhr) { $.each(data, function(i, data) { introPage(data); }); }).fail(function(Error) { alert(Error.status); }); function introPage(data ) { $.getJSON('myphp.php?jsoncallback=?&template='+testTemplate, function(msg) { // my operations }).error(function(data) { }); } We have .fail() in getJSON to catch the

$.getJSON parsererror trying to call API

主宰稳场 提交于 2019-12-04 05:50:24
问题 I'm trying to use the Clipped API (http://clipped.me/api.html) that returns JSON but am running into some trouble. I'm using getJSON, and in Chrome's JS console I get these error messages: Resource interpreted as Script but transferred with MIME type text/html: "http://clipped.me/algorithm/clippedapi.php?url=callback=jQuery1910859611126…emo-day-2013-still-looking-for-the-next-airbnb-or-dropbox/&_=1364420105379". Uncaught SyntaxError: Unexpected identifier Request Failed: parsererror, Error:

return value from getJSON function

◇◆丶佛笑我妖孽 提交于 2019-12-04 05:19:55
问题 I have a function with jquery getJSON and i need the return the result value back (to Use it somewhere else) Here is the code: function getval(){ jQuery.getJSON('http://data.mtgox.com/api/1/BTCUSD/ticker?callback=?', function(data) { // We can't use .return because return is a JavaScript keyword. return data['return'].avg.value; }); } $(function () { $(document).ready(function() { alert (getval()); }); }); This is doesn't work :( i know i can call external function from inside the getJSON

getJSON or AJAX requests not working with IE9

房东的猫 提交于 2019-12-04 03:46:11
I have been trying to solve this problem for hours (searched here as well but none of the solutions worked) so I had no other option but to hope for someone to tell me why this is happening and how can I fix it. This is a simple code that works with Firefox but not with IE9 (don't have other versions) Example code is here: http://jsfiddle.net/z5b2J/ Source is this one: $.ajax({ url: "http://query.yahooapis.com/v1/public/yql?q=select%20script%20from%20html%20where%20url%3D%27https%3A%2F%2Ftesting.website.com%2F%3Fcid%3D48hgfd45430DD%26id%3D4830F8CF0454312%27&format=json&diagnostics=true&_maxage

'jQuery.getJSON' not working in Internet Explorer 8

混江龙づ霸主 提交于 2019-12-03 21:16:49
I am using jQuery.getJSON to fetch the Facebook friends list, but I am not getting it. It works perfectly in Firefox and Chrome, but it is not working in Internet Explorer 8. jQuery.getJSON("https://graph.facebook.com/me/friends?access_token="+aToken, function(data) { alert(data); } ); Also after doing a little more research I tried with this code also: jQuery.ajax({ url:"https://graph.facebook.com/me/friends?access_token="+aToken, type: 'json', success: function(json) { alert(json); } }); leomeurer Try this to handle the error: jQuery.getJSON("https://graph.facebook.com/me/friends?access

Call ASP.NET Web API from code-behind

倾然丶 夕夏残阳落幕 提交于 2019-12-03 12:45:03
问题 How would I call an ASP.NET Web API directly from code-behind? Or should I be calling my javascript function that calls the getJSON method from code-behind? I usually have something like: function createFile() { $.getJSON("api/file/createfile", function (data) { $("#Result").append('Success!'); }); } Any pointers appreciated. TIA. *I'm using WebForms. 回答1: If you must call the web service itself, you can try using HttpClient as described by Henrik Neilsen. Updated HTTPClient Samples A basic