xmlhttprequest

Make AJAX call wait for event in php

半世苍凉 提交于 2020-01-13 05:09:05
问题 I do not know if my tile line is clear enough... My problem is: I have a JS application that needs to wait for an event on the server. At the moment it polls continuous the server data via XMLHttpRequest every second. What I am thinking about is: Is it possible to make the call wait until for example a variable in PHP changes? I hope that my question is clear enough. Thanks! 回答1: You're looking for long polling (colloquially known as Comet). There are many examples on SO and elsewhere. http:/

Two xmlHttpRequests in a single page

陌路散爱 提交于 2020-01-13 04:56:13
问题 I'm fairly new to ajax but am trying to implement two simple calls to dynamically changes two separate divs on a page using javascript. I have no problems using one call at a time, but when I use two it seems like the second xmlhttprequest takes over the first and writes into both divs. I've read and tried using the fixes listed on these two other posts both neither seem to work in my case: Sending two Ajax requests to two different PHP scripts from single javascript function Using two

Open local html pages using http to test

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 03:58:10
问题 I am coding a webapp and i get this kind of errors with chrome : XMLHttpRequest cannot load file:///C:\Users\Tordah\Desktop\foobar.xml. Cross origin requests are only supported for HTTP. & Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load I believe i get this error because the HTML file is accessed with file: protocol and not http: protocol which creates compatibility issues with XMLHttpRequest (That's a guess). I would like to know if there's any ways of

Sending authorization headers with jquery and ajax

让人想犯罪 __ 提交于 2020-01-13 02:09:06
问题 I have looked at the following questions here on stackoverflow with no luck in what im trying to do. Ajax Authorization Request headers fails again and again jQuery Ajax Unauthorized 401 Error Sending credentials with cross-domain posts? Here is my code that I currently have: $(document).ready(function() { $.ajax({ url: 'http://sample.domain.com/script.php?name1=value1&jsonp=?', type: 'GET', dataType: 'json', contentType: "application/json", beforeSend: function(xhr) { xhr.setRequestHeader(

True difference between HttpRequest and XMLHttpRequest

微笑、不失礼 提交于 2020-01-12 18:47:59
问题 Note before reading This is not a duplicate of what-are-differences-between-xmlhttprequest-and-httprequest And for info, I tried this lib without success, because it copies the structure of the XMLHttpRequest but doesn't actually act like it. I wonder what is the true network difference between HttpRequest from Node and XMLHttpRequest from a browser. If I just watch the XMLHttpRequest inside chrome's devtools, I can't see any X-Requested-with header in the request. Besides, there's an online

$.ajax()方法详解

只谈情不闲聊 提交于 2020-01-12 15:59:58
$.ajax()方法详解 1.url : 要求为String类型的参数,(默认为当前页地址)发送请求的地址。 2.type : 要求为String类型的参数,请求方式(post或get)默认为get。注意其他http请求方法,例如put和delete也可以使用,但仅部分浏览器支持。 3.timeout : 要求为Number类型的参数,设置请求超时时间(毫秒)。此设置将覆盖$.ajaxSetup()方法的全局设置。 4.async : 要求为Boolean类型的参数,默认设置为true,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为false。注意,同步请求将锁住浏览器,用户其他操作必须等待请求完成才可以执行。 5.cache : 要求为Boolean类型的参数,默认为true(当dataType为script时,默认为false),设置为false将不会从浏览器缓存中加载请求信息。 6.data : 要求为Object或String类型的参数,发送到服务器的数据。如果已经不是字符串,将自动转换为字符串格式。get请求中将附加在url后。防止这种自动转换,可以查看  processData选项。对象必须为key/value格式,例如{foo1:"bar1",foo2:"bar2"}转换为&foo1=bar1&foo2=bar2。如果是数组

Chrome -> Inspect element -> Network (XHR) -> Preview Tab (HTML) issue

江枫思渺然 提交于 2020-01-12 08:05:18
问题 I am having a problem with that preview tab in network section. When HTML is returned I am seeing the raw HTML in both preview and response. Sometimes, but very rarely, I HTML is rendered properly in Preview tab. Am I doing something wrong or it's just some Chrome bug? Thanks 回答1: I was testing this as well. What did it for me was adding the http header. header('HTTP/1.1 500 Internal Server Error'); Then of course some proper markup formatting. But the status code was what I needed to

Chrome -> Inspect element -> Network (XHR) -> Preview Tab (HTML) issue

与世无争的帅哥 提交于 2020-01-12 08:05:10
问题 I am having a problem with that preview tab in network section. When HTML is returned I am seeing the raw HTML in both preview and response. Sometimes, but very rarely, I HTML is rendered properly in Preview tab. Am I doing something wrong or it's just some Chrome bug? Thanks 回答1: I was testing this as well. What did it for me was adding the http header. header('HTTP/1.1 500 Internal Server Error'); Then of course some proper markup formatting. But the status code was what I needed to

XHR Upload Progress is 100% from the start

烈酒焚心 提交于 2020-01-12 03:07:09
问题 I'm trying out the new XMLHTTPRequestUpload feature to upload some files to a php script, it mostly works fine, the upload starts, I get the finish response etc - but the progress doesn't seem to work. Looking that the event.loaded value - In firefox I seem to get a random value between 0 and the file size; in Chrome (where I'm mostly working) I get the total file size, even though the readystate hasn't reached '4' and the Developer Tools window still shows the file to be loading? Any ideas?

XMLHttpRequest、fetch、Ajax 三种前后端交互方法

牧云@^-^@ 提交于 2020-01-12 00:19:27
一、原生XMLHttpRequest方法 const BASE_URL = “http://10.2.0.150” 1.原生实现 GET /* // 1. 创建请求对象 let xhr = new XMLHttpRequest(); // 2. 配置请求 // -> xhr.open(method, url, sync) xhr.open(“GET”, ${BASE_URL}/heros?id=1 , true); // -> 设置响应类型 xhr.responseType = “json”; // -> 设置请求超时时间 xhr.timeout = 10000; // 3. 发送请求 xhr.send(); // 4. 事件监听 // -> 请求完成 xhr.onload = function() { // readyState 请求状态 // status 状态码 if(xhr.status == 200) { // 打印结果 console.log(xhr.response); }else { console.log( XMLHttpRequest_ERROR_STATUS:${xhr.status} ); } }*/ 2.原生实现 POST // 1. 创建请求对象 let xhr = new XMLHttpRequest(); // 2. 配置请求 // -> xhr