xmlhttprequest

What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get

守給你的承諾、 提交于 2019-12-17 08:04:05
问题 How can I find out which method is best for a situation? Can anybody provide some examples to know the difference in terms of functionality and performance? 回答1: XMLHttpRequest is the raw browser object that jQuery wraps into a more usable and simplified form and cross browser consistent functionality. jQuery.ajax is a general Ajax requester in jQuery that can do any type and content requests. jQuery.get and jQuery.post on the other hand can only issue GET and POST requests. If you don't know

NETWORK_ERROR: XMLHttpRequest Exception 101

戏子无情 提交于 2019-12-17 07:27:28
问题 I am getting this Error NETWORK_ERROR: XMLHttpRequest Exception 101 when trying to get XML content from one site. Here is my code: var xmlhttp; if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } if (xmlhttp==null) { alert ("Your browser does not support XMLHTTP!"); return; } xmlhttp.onReadyStateChange=function() { if(xmlhttp.readyState==4) { var value =xmlhttp.responseXML; alert(value); } } xmlhttp.open("GET",url,false); xmlhttp.send(); //alert(xmlhttp.responseXML); } xmlhttp.open(

Restrictions of XMLHttpRequest's getResponseHeader()?

为君一笑 提交于 2019-12-17 07:25:31
问题 I've noticed that the results of and XMLHttpRequest.getResponseHeader() don't always match the real headers returned (if the request is made in a regular manner). For example, assume I'm making an xhr request for https://foo.example.com/api/resource/100 . In Chrome's developer console, under 'Network', I can see the response being made -- I can also see all of the response headers (say, 10). However (copy-pasted console): > response XMLHttpRequest > response.getAllResponseHeaders(); "content

d3.json doesn't return my data array in D3 v4

为君一笑 提交于 2019-12-17 06:55:08
问题 I'm using d3.json to load a JSON file containing my data, like this: var data = d3.json(url, callback) If I do a console.log(data) I can see that data is neither empty nor null . However, it doesn't seem to contain my data array, but something else instead. What am I doing wrong here? Note: this is a self-answered question, trying to provide a "canonical" Q&A on a subject that has been touched on by many previous questions and not (clearly) explained by the API. The answer below was written

Chrome cancels CORS XHR upon HTTP 302 redirect

旧时模样 提交于 2019-12-17 06:35:11
问题 It looks like according to the CORS Spec, GET and POST requests should transparently follow 302 redirects. But Chrome is canceling my request. Here's the JS that does the request: var r = new XMLHttpRequest(); r.open('GET', 'https://dev.mysite.com/rest', true); r.send(); Here's what should happen: Client: XHR POST request to /rest Server: responds with HTTP 302 redirect to /rest/ Client: Follow that redirect But after step 2, Chrome cancels the request. If there was no HTTP 302, the request

“not well-formed” error in Firefox when loading JSON file with XMLHttpRequest

天大地大妈咪最大 提交于 2019-12-17 06:07:41
问题 I'm getting a "not well-formed" error in the error console of Firefox 3.0.7 when the JavaScript on my page loads a text file containing an object in JavaScript Object Notation format. If the file contains nothing but the JSON object, it produces the error. If I wrap the object in <document></document> tags it does not produce the error. The request succeeds either way, so I could just ignore it, but I don't want my error log filling up with these messages. Here is some example code to

Open webpage, select all, copy into sheet

守給你的承諾、 提交于 2019-12-17 05:14:10
问题 I have searched high and low for something that will work for me on this, no luck! Any help would be so much appreciated! :) Looking to copy Stock options data from Barcharts.com and paste into excel sheet. here's where I'm at: Sub CopyTables() Dim ie As Object Dim I As Long I = 0 Set ie = CreateObject("InternetExplorer.Application") ie.navigate "https://www.barchart.com/stocks/quotes/GOOG/options?moneyness=allRows&view=sbs&expiration=2018-02-23" ie.Visible = True Do While ie.Busy And Not ie

“Origin null is not allowed by Access-Control-Allow-Origin” in Chrome. Why? [duplicate]

空扰寡人 提交于 2019-12-17 04:16:33
问题 This question already has answers here : XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless) (9 answers) Closed 5 years ago . I am working on some Javascript to run locally on my PC. I am using a jQuery CSV plugin (http://plugins.jquery.com/project/csv) to load load a csv file into javascript arrays. The script is simple: $(function(){ $.get("file.csv", function(data){ stuff = $.csv()(data); }) }) In Firefox it works fine but in Chrome

Is onload equal to readyState==4 in XMLHttpRequest?

不想你离开。 提交于 2019-12-17 03:50:24
问题 I am confuse about the xhr return event, as I can tell, there are not so much different between onreadystatechange --> readyState == 4 and onload, is it true? var xhr = new XMLHttpRequest(); xhr.open("Get", url, false); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { /* do some thing*/ } }; xhr.send(null); or xhr.onload = function() { /* do something */ } 回答1: It should be the same thing. onload was added in XMLHttpRequest 2 whereas onreadystatechange has been around since

Web scrape using XHR from siriusxm.com

五迷三道 提交于 2019-12-17 03:44:21
问题 I need to pull the currently playing artist and song from http://www.siriusxm.com/siriusxmhits1. I can get this to work navigating to the website with Internet Explorer but it takes too long so I have tried using WINHTTP.WinHTTPRequest.5.1 and MSXML2.serverXMLHTTP but neither pulls the specific data I'm looking for. I think I'm close but am missing something. Below is the HTML snippet: <div id="on-the-air-content" style="display: block;"> <div class="module-content theme-color-content-bg