xmlhttprequest

XMLHttpRequest异步对象

混江龙づ霸主 提交于 2020-01-27 09:17:35
XMLHttpRequest 异步对象 参考链接: MDN https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX 一个成功的响应:有两个条件 1:服务器成功响应了。 2:异步对象的响应状态为4。 xhr.status == 200 可以获取当前服务器的响应状态。 xhr.readyState == 4。异步对象发送请求给服务器,服务器响应数据内容解析完毕,可以使用了。 xhr.responseText 服务器返回的数据 或者是XML数据格式。 readystatechange 监听客户端异步对象状态变化事件 readyState 可以检测 XHR 对象的 readyState 属性,该属性表示请求 / 响应过程的当前活动阶段 超时预定 XMLHttpRequest 2 级规范中为 XHR 对象添加了一个 timeout 属性,表示请求在等待响应多少毫秒之后就终止。 在给 timeout 设置一个数值后,如果在规定的时间内浏览器还没有接收到响应,那么就会触发 timeout 事件, 进而会调用 ontimeout 事件处理程序。如果在超时之后还去访问status属性就会导致错误,可以在status中封装 一个try-catch语句。 进度事件 load事件: 简化了异步交互模型,代替了readystatechange

AJAX XHR

被刻印的时光 ゝ 提交于 2020-01-27 02:56:18
AJAX - 创建 XMLHttpRequest 对象 XMLHttpRequest 是 AJAX 的基础。 XMLHttpRequest 对象 所有现代浏览器均支持 XMLHttpRequest 对象(IE5 和 IE6 使用 ActiveXObject)。 XMLHttpRequest 用于在后台与服务器交换数据。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。 创建 XMLHttpRequest 对象 所有现代浏览器(IE7+、Firefox、Chrome、Safari 以及 Opera)均内建 XMLHttpRequest 对象。 创建 XMLHttpRequest 对象的语法: variable = new XMLHttpRequest ( ) ; 老版本的 Internet Explorer (IE5 和 IE6)使用 ActiveX 对象: variable = new ActiveXObject ( "Microsoft.XMLHTTP" ) ; 为了应对所有的现代浏览器,包括 IE5 和 IE6,请检查浏览器是否支持 XMLHttpRequest 对象。如果支持,则创建 XMLHttpRequest 对象。如果不支持,则创建 ActiveXObject : var xmlhttp ; if ( window . XMLHttpRequest )

ExtJS AJAX: XMLHttpRequest cannot load

≯℡__Kan透↙ 提交于 2020-01-25 20:19:12
问题 New to ExtJS. All of the files below exist within the same directory (code below) - not sure why I'm getting the following error. Do I need to be using a server even though the data is stored in the directory? I'm getting the following on the Chrome console: XMLHttpRequest cannot load file:///C:/Users/Jeff/Development/workspace_extjs/Chapter%2007/JSON_data/data.json?_dc=1406036611330&page=1&start=0&limit=25. Received an invalid response. Origin 'null' is therefore not allowed access. JSON

Is there a way to force an XMLHttpRequest to use HTTP/1.1?

三世轮回 提交于 2020-01-25 09:37:06
问题 I have a server endpoint that supports both HTTP/1.1 and HTTP2. For testing purposes, I want to try downloading content from the endpoint with both HTTP/1.1 and HTTP2 connections, possibly at the same time. When I request data from the endpoint with an XMLHttpRequest, it automatically uses HTTP2, without me including the Connection: Upgrade header. Is there a way to force an XMLHttpRequest to use HTTP/1.1 for the underlying TCP connection? What about other protocols, such as Quic or SPDY? 回答1

XmlHttpRequest错误:Access-Control-Allow-Origin不允许使用原点null

被刻印的时光 ゝ 提交于 2020-01-25 02:36:02
我正在开发一个页面,该页面通过 jQuery 的AJAX支持从Flickr和Panoramio中提取图像。 Flickr方面运行良好,但是当我尝试从Panoramio进行 $.get(url, callback) 时,我在Chrome的控制台中看到一个错误: XMLHttpRequest 无法加载 http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback=processImages&minx=-30&miny=0&maxx=0&maxy=150 。 Access-Control-Allow-Origin不允许使用Origin null。 如果我直接从浏览器查询该URL,它将正常工作。 这是怎么回事,我可以解决这个问题吗? 我是在错误地编写查询,还是Panoramio这样做妨碍了我的工作? Google并未在 错误消息中 显示任何有用的匹配项。 编辑 这是一些显示问题的示例代码: $().ready(function () { var url = 'http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback

Default URL for XMLHttpRequest

假如想象 提交于 2020-01-24 23:13:26
问题 Similarly to how a <form> with either no action attribute or an empty one, is it consistent and reliable behaviour that an XMLHttpRequest with en empty string given to the URL parameter will request the current URL? 回答1: After experimentation, it appears the answer is "No". In fact, the URL argument is required and will cause an error. 来源: https://stackoverflow.com/questions/12955019/default-url-for-xmlhttprequest

too many xhr requests in chrome

怎甘沉沦 提交于 2020-01-24 20:44:06
问题 I have a tight loop that fetches PNG files via xhr2. Works fine in FF and IE10. In Chrome when I list of files hits about 5,500 I start getting xhr errors. I like the async interface since I am interleaving these requests with local indexedDB store requests. Code below (I am using xhr2lib for fetches and PouchDB for the IndexedDB API). I know that it is the XHR2 that is failing, since when this works, in Chrome, all the XHR2 calls are processed before the SaveDB() calls. When It fails, I

How to send api requests in real time in JS?

家住魔仙堡 提交于 2020-01-24 19:37:05
问题 With this XHR request it would only send request once, if this is done with setTimeout it can repeatedly send request but how to do that in real time? Like on some websites we can see real time bitcoin prices. I read about EventSource but can't understand how it's used. var xhr = new XMLHttpRequest() xhr.onload = function(){ if(this.status == 200){ document.write(this.responseText)' } } xhr.open("GET","https://api.coindesk.com/v1/bpi/currentprice/USD.json",true); xhr.send(); 回答1: With XHR,

422 Unprocessable Entity in rails

点点圈 提交于 2020-01-23 19:02:05
问题 I am trying to implement upload a file functionality in my ror website. The file is uploaded by drag and drop on a div I can access the file info using e.originalEvent.dataTransfer.files[0].name e.originalEvent.dataTransfer.files[0].size and for uploading the file upload(e.originalEvent.dataTransfer.files[0]); function upload(myfile) { var fd = new FormData(); fd.append("name", myfile.name); fd.append("fileToUpload", myfile); var xhr = new XMLHttpRequest(); xhr.open("POST", "upload_main_file"

Need a delay function javascript

青春壹個敷衍的年華 提交于 2020-01-23 07:47:23
问题 Hi im currently making a xmhhttp request, but the site takes some time to load, so I only get the ReadyState = 3 and status = 200. So I need something that waits until the readystate = 4, but I want to limit this function so that it only checks once a second if the readystate = 4, else do nothing. How can such a delay function look like? if (xmlhttp.readyState==4 && xmlhttp.status==200)//Add the delay here so that the else doesn't occur { var txt=xmlhttp.responseText; ..... else { document