xmlhttprequest

XMLHttpRequest to read an external file

被刻印的时光 ゝ 提交于 2019-12-20 02:09:12
问题 I want to retrieve the data contained in a text file (from a given URL) through JavaScript (running on the client's browser). So far, I've tried the following approach: var xmlhttp, text; xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', 'http://www.example.com/file.txt', false); xmlhttp.send(); text = xmlhttp.responseText; But it only works for Firefox. Does anyone have any suggestions to make this work in every browser? Thanks 回答1: IT works using xmlhttp=new ActiveXObject("Microsoft

FormData not working in Internet Explorer?

半腔热情 提交于 2019-12-19 21:24:23
问题 function uploadPhoto(file) { if (!file || !file.type.match(/image.*/)){ if(!file){ postStatus(); } else { return; } } var fd = new FormData(); fd.append("image", file); fd.append("privacy", document.getElementById('privacy-handler').value); var xhr = GetXmlHttpRequest(); xhr.open("POST", "url here"); slideUp('photo-upload'); slideDown('photo-manager-txt'); document.getElementById("photo-manager-txt").innerHTML='<i>Please wait a moment while we process your photo.</i>'; xhr.onload = function()

What am I missing in the XMLHttpRequest?

╄→гoц情女王★ 提交于 2019-12-19 17:34:38
问题 I'm completely new to the javascript and ajax world but trying to learn. Right now I'm testing the XMLHttpRequest and I can't make work even the simplest example. This is the code I'm trying to run <script type="text/javascript"> function test() { xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200){ var container = document.getElementById('line'); container.innerHTML = xhr.responseText; } else { alert(xhr.status); } } xhr.open('GET',

phantomjs - Cookie is not being sent for any XHR/POST/GET AJAX requests

删除回忆录丶 提交于 2019-12-19 12:28:07
问题 I found an interesting issue when attempting to login using PhantomJS. I'm at a loss as to why it's actually occurring. Basically you start up a remote debugger like so: /usr/local/bin/phantomjs --web-security=no --remote-debugger-port=13379 --remote-debugger-autorun=yes /tmp/test.js Within the remote debugger: > location.href = "https://www.mysite.com/login" > $('input[name="username_or_email"]').val('blah@email.com') > $('input[name="password"]').val('wrongpassword') > $('button[type=

How do I test ajax POST request with RSpec?

风流意气都作罢 提交于 2019-12-19 12:25:17
问题 I just want to test ajax request on controller spec. The product code is below. I'm using Devise for authentication. class NotesController < ApplicationController def create if request.xhr? @note = Note.new(params[:note]) if @note.save render json: { notice: "success" } end end end end And spec is below. describe NotesController do before do user = FactoryGirl.create(:user) user.confirm! sign_in user end it "has a 200 status code" do xhr :post, :create, note: { title: "foo", body: "bar" },

Jquery error : too much recursion

折月煮酒 提交于 2019-12-19 11:57:54
问题 I'm trying to create a file upload system implementing client side encryption using CryptoJS. The problem I'm having is that execution of the script is stopped by the following error in Firebug's console : too much recursion I have spent half of the day trying to resolve the problem, removing the var jqxhr = $.ajax part removes the error but removes posting functionality from my script. I have tried removing all the encryption lines, separating into different functions, but nothing seems to

XHR abort doesn't stop file uploading

最后都变了- 提交于 2019-12-19 10:47:30
问题 I've made an XHR-based file uploader with progressbar, and I would like to add a feature to cancel the upload before it fully uploaded. The simlified code (runs after DOM ready): var xhr; $('#upload').click(function(){ var file = $('#file').get(0).files[0]; xhr = new XMLHttpRequest(); xhr.upload.onprogress = function(event){ if (event.lengthComputable){ var percent = event.loaded / event.total; $('#uploadpercent').html(Math.round(percent * 100) + "%"); } }; xhr.abort = function(){ console.log

Using FormData object, the server receives an empty POST

China☆狼群 提交于 2019-12-19 10:09:00
问题 I'm attempting to send one file and one text variable to my server with the FormData object. Looking at the Network tab in Chrome's developer tools, I can see that the file and variable are being sent. However, I've tried var_dump() on the $_POST and $_FILES variables, and both are shown as empty arrays. Here's the code I'm using for the form: var image_upload = document.getElementById("image_upload"); if(image_upload.value == '') { alert("Please select a file to upload."); } else { alert("in

Getting '400 Bad Request' when using multipart/form-data as Content-Type in XHR

做~自己de王妃 提交于 2019-12-19 09:45:20
问题 I have an AJAX request that sends out some data. The data respects the multipart/form-data specification. The problem I'm facing is that the browser sets the Content-Type header to text/plain and it should be multipart/form-data. I've tried doing this: request.setRequestHeader("Content-Type", "multipart/form-data"); but this gives out an 400 Bad Request error. If I do request.setRequestHeader("Content-Typexxxx", "multipart/form-data"); there is no error, the "Content-Typexxxx" header is set

XMLHttpRequest upload.onprogress instantly complete

偶尔善良 提交于 2019-12-19 07:23:07
问题 I'm trying to make a file uploader with HTML5 with a progress meter. Here's my code: <!DOCTYPE html> <html> <head> <title>Test Progress Meter</title> <script type="text/javascript"> function submitFile(){ var blobOrFile = document.getElementById("fileInput").files[0]; var xhr = new XMLHttpRequest(); xhr.onload = function(e) { alert("finished!"); }; xhr.upload.onprogress = function(e) { if (e.lengthComputable) { document.getElementById("statusBox").innerHTML = e.loaded + " / " + e.total; } };