xmlhttprequest

使用JavaScript的XMLHttpRequest发送POST、GET请求以及接收返回值

不羁的心 提交于 2019-12-30 21:18:46
使用XMLHttpRequest对象分为4部完成: 1.创建XMLHttpRequest组建 2.设置回调函数 3.初始化XMLHttpRequest组建 4.发送请求 实例代码: [javascript] var userName; var passWord; var xmlHttpRequest; //XmlHttpRequest对象 function createXmlHttpRequest(){ if(window.ActiveXObject){ //如果是IE 浏览器 return new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ //非IE浏览器 return new XMLHttpRequest(); } } function onLogin(){ userName = document.f1.username.value; passWord = document.f1.password.value; var url = "LoginServlet?username="+userName+"&password="+passWord+""; //1.创建XMLHttpRequest组建 xmlHttpRequest = createXmlHttpRequest(); //2

Javascript isn't uploading binary data

筅森魡賤 提交于 2019-12-30 18:56:29
问题 My javascript function only uploads text files correctly. Can anybody help me figure out how to make it also accept images etc. ? function fileUpload(files) { if (!files.length) { fileList.innerHTML = "<p>No files selected!</p>"; } else { var list = document.createElement("ul"); for (var i = 0; i < files.length; i++) { //Set vars var file = files[i], fileName = file.name, fileSize = file.size, fileData = file.getAsBinary(), boundary = "xxxxxxxxx", uri = "receive.php", //Create file info HTML

XML-RPC HTTP request with App Inventor?

拟墨画扇 提交于 2019-12-30 14:52:48
问题 I am trying to build out an app that will communicate with Tapatalks API, it uses XML-RPC HTTP requests, I can do post/get requests with the web component. I cannot find anything on modifying the web component/Blocks to create said XML-RPC encoding. Any resources? Tips of what to search, or insight would be appreciated. This is the API php code I am trying to interact with https://github.com/tapatalk/tapatalk-phpbb3/blob/master/root/mobiquo/function/login.php Here is my app blocks currently

你真的会使用XMLHttpRequest吗?

99封情书 提交于 2019-12-30 14:18:25
一、前言 看到标题时,有些同学可能会想:“我已经用 xhr 成功地发过很多个 Ajax 请求了,对它的基本操作已经算挺熟练了。” 我之前的想法和你们一样,直到最近我使用xhr时踩了不少坑儿,我才突然发现其实自己并不够了解 xhr ,我知道的只是最最基本的使用。 于是我决定好好地研究一番 xhr 的真面目,可拜读了不少博客后都不甚满意,于是我决定认真阅读一遍W3C的 XMLHttpRequest 标准。看完标准后我如同醍醐灌顶一般,感觉到了从未有过的清澈。这篇文章就是参考W3C的 XMLHttpRequest 标准和结合一些实践验证总结而来的。 二、 Ajax 和 XMLHttpRequest 我们通常将 Ajax 等同于 XMLHttpRequest ,但细究起来它们两个是属于不同维度的2个概念。 以下是我认为对 Ajax 较为准确的解释:(摘自what is Ajax) 以下是我认为对Ajax较为准确的解释:(摘自what is Ajax) AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS,

XHR / Post Request using D3

你。 提交于 2019-12-30 10:30:51
问题 I was doing a research on how to make POST requests using the amazingly powerful D3 (which I can fully fully recommend for data visualization) and found the xhr2 branch where the authors of D3 are currently working on xhr POST request (and other request types) support. Seems like it is a brand new feature as the merge request is from yesterday (18 September 2012) :) And as curious I am I already wanted to try it out, using the following code sequence (which I have from this location) d3.text(

XMLHttpRequest: How to force caching?

强颜欢笑 提交于 2019-12-30 10:05:33
问题 I'm newer to XMLHttpRequests since I've previously used jQuery's AjAX method. However I need to work in a web worker and now I have to use the classic XMLHttpRequest for performance issues. I'm trying to rebuild the cache -property from jquery. If cache should be disabled I add this: xhr.setRequestHeader("Cache-Control", "no-cache"); But what header should I set if I want to force caching (not prevent)? 回答1: There are a variety of headers you can set to encourage caching, but they (including

custom XMLHttpRequest.prototype.open

醉酒当歌 提交于 2019-12-30 07:04:12
问题 var open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) { this.addEventListener("readystatechange", function(event) { if(this.readyState == 4){ var self = this; var response = { method: method, uri: uri, responseText: self.responseText }; console.log(response); } else { console.log(this.readyState); } }, false); open.call(this, method, uri, async, user, pass); }; I am trying to listen for XHR before they are being sent. Something

custom XMLHttpRequest.prototype.open

北战南征 提交于 2019-12-30 07:04:06
问题 var open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) { this.addEventListener("readystatechange", function(event) { if(this.readyState == 4){ var self = this; var response = { method: method, uri: uri, responseText: self.responseText }; console.log(response); } else { console.log(this.readyState); } }, false); open.call(this, method, uri, async, user, pass); }; I am trying to listen for XHR before they are being sent. Something

Error: __tcp_connection_write_eof_block_invoke Write close callback received error - iOS 10

╄→尐↘猪︶ㄣ 提交于 2019-12-30 06:42:18
问题 While sending XML base API Request to ONVIF Camera. It worked fine on ios 9 device, but giving '500 Internal Error' on iOS 10. XCode 8 Console prints below error messages: 2016-09-30 12:39:51.295419 VCPlugin[278:10183] [] nw_socket_get_input_frames recvmsg(fd 12, 1024 bytes): [54] Connection reset by peer 2016-09-30 12:39:51.301221 VCPlugin[278:10228] [] nw_socket_write_close shutdown(12, SHUT_WR): [57] Socket is not connected 2016-09-30 12:39:51.301307 VCPlugin[278:10228] [] nw_endpoint_flow

How does this Cross Domain ajax request work?

﹥>﹥吖頭↗ 提交于 2019-12-30 06:32:12
问题 I'm looking at this question and in it is a link to http://hacks.mozilla.org/2011/03/the-shortest-image-uploader-ever/ which has the following code: var fd = new FormData(); fd.append("image", file); // Append the file fd.append("key", "6528448c258cff474ca9701c5bab6927"); // Get your own key: http://api.imgur.com/ // Create the XHR (Cross-Domain XHR FTW!!!) var xhr = new XMLHttpRequest(); xhr.open("POST", "http://api.imgur.com/2/upload.json"); // Boooom! xhr.onload = function() { // Big win!