xmlhttprequest

How to catch the error thrown by an invalid URL using XMLHttpRequest

和自甴很熟 提交于 2020-01-05 07:04:13
问题 I have not worked much with the XMLHttpRequest object in JavaScript . I am new to it. I have done many jQuery Ajax calls, but have not worked in much detail with the XMLHttpRequest object. I am working through a book where they give some sample code using this object. Here is some code the book uses when trying to deal with errors. It is supposed to catch the error thrown by the incorrect URL. But I can't get it to go it the catch clause : var httpRequest = new XMLHttpRequest(); try {

Safari 5 Extension XMLHttpRequest Error: INVALID_STATE_ERR: DOM Exception 11

牧云@^-^@ 提交于 2020-01-05 06:42:25
问题 I am experimenting with the new Safari 5 extensions JS API and I am having an issue right from the ground up, I want to use an XMLHttpRequest to get an RSS feed from a website however upon the .send() it immediatly kicks off errors: Failed to load resource: cancelled Then looking at the XMLHttpRequest object is says in status: Error: INVALID_STATE_ERR: DOM Exception 11 I don't know why but this is my code, I hope I can get some advice as to whats going wrong: var xml = new XMLHttpRequest();

How to retry an xhr request which returns a promise recursively for atleast n times on status 0

本秂侑毒 提交于 2020-01-05 05:31:06
问题 I have written the below piece of code. makeRequest gets called and I want to retry this when xhr status is 0. The problem is I am not able to resolve the correct promise, the retry logic fetches the correct response in nth attempt but fails to propagate to the caller method. How do I resolve this issue. var makeRequest = function(method, urlToBeCalled, payload) { var deferred = $q.defer(); var xhr = new XMLHttpRequest(); xhr.open(method, encodeURI(urlToBeCalled), true); setHttpRequestHeaders

xhr response with for loop not working

霸气de小男生 提交于 2020-01-05 02:50:10
问题 i have xhr with for loop and it work very rare for(var i = 0; i < this.files.length; i++) { var xhr = new XMLHttpRequest(); xhr.upload.onprogress = function(e) { }; xhr.onreadystatechange = function(e) { if(this.readyState === 4) { console.log(xhr.responseText); } }; var formdata = new FormData(); formdata.append("files", this.files[i]); console.log(this.files[i]); xhr.open('POST', 'slike.php'); xhr.send(formdata); } I'm calling this slike.php. And it work very well, but on responseText, it's

Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel

大兔子大兔子 提交于 2020-01-04 15:29:43
问题 My problem is as follows: On a page, I am doing multiple (6) ajax calls (via jQuery) to fetch some data at the same time (using php wrapper to fetch the data via the calls) The requests are made at the same time and it takes them 10-20 seconds to complete If user clicks on any of the links to go somewhere else (to some other page), I can see that all the calls that didn't complete get cancelled However, the browser still waits for 20 seconds to navigate to the other page - it is like it is

Monitoring progress in synchronous XMLHttpRequest calls

十年热恋 提交于 2020-01-04 09:08:19
问题 On the clientside i have a File-Dropzone (HTML5 File-API) where the user can drop multiple files that should be uploaded to the server. For each file a new XMLHttpRequest Object is created and the file is sent asynchronously to the server. I'm monitoring the progress through a progress event Listener on the xhr.upload object. The problem is, that as of now the server side needs to get the files synchronously because there is some calculation happening that must be done one file after another

Automatic web-page refresh memory leak using XMLHttpRequest

可紊 提交于 2020-01-04 06:29:11
问题 Greetings, I've been working on a web-interface for some hardware that uses an 8-bit microcontroller. The web page uses HTML, javascript, JSON and XHR (XMLHttpRequest) for its communications. What I'm trying to do is create a page that updates every 250mS with new values from the controller using setInterval so that the web page gets updated 'real-time' to make it feel more like an application to the user. I've gotten it to work for the most part, but found that there's a memory leak

Firefox augments the content-type of XMLHttpRequest

我们两清 提交于 2020-01-04 05:25:24
问题 How can FireFox be forced to use a specific content type for XMLHttpRequest without appending the charset parameter after the type itself? I am using FireFox 15 to extract some data out of a very custom http server. The server takes JSON from the POST body and responds with another JSON. The server accepts only "Content-Type: application/json" as valid content type. Anything after except this exact header will not be recognized by the server as valid content type. When I use the below code in

Cross domain issue with .ajax (JQuery) to a domain I own — simple PHP page

杀马特。学长 韩版系。学妹 提交于 2020-01-04 05:22:06
问题 So I know this is a common problem and have seen a lot of people talking about it but feel that my situation is unique and maybe not as involved as others. I have a host website and trying to build an iPhone app with JQ and PhoneGap. I want people to be able to pass their score to my home domain from the app but am getting the dreaded: "Origin null is not allowed by Access-Control-Allow-Origin." when I try and call this: $.ajax({ type: "POST", url: 'http://www.homesite.com/thephppage.php',

Uploading files using XMLHttpRequest

落爺英雄遲暮 提交于 2020-01-04 04:29:06
问题 I'm trying to use a drag and drop plugin in javascript to upload files using ajax. <script> DnD.on('#drop-area', { 'drop': function (files, el) { el.firstChild.nodeValue = 'Drag some files here.'; var names = []; [].forEach.call(files, function (file, i) { names.push(file.name + ' (' + file.size + ' bytes)'); var xhr = new XMLHttpRequest(); xhr.open('POST','upload.php'); xhr.setRequestHeader("Content-type", "multipart/form-data"); xhr.send(file); console.log(xhr.responseText); }); document