标签: xmlhttprequest

IE8 XmlHttpRequest调试

我正在寻找一些方法来优雅地检查IE8中的XmlHttpRequests.我不介意插件或外部程序.我还没有发现任何与Firebug一样好的东西.

我已经尝试过Julien Couvreur的书签调试器,但它似乎与Prototype不兼容.朱利安的剧本

javascript ajax xmlhttprequest internet-explorer-8 ie-developer-tools

9
推荐指数
1
解决办法
1万
查看次数

$ _SERVER ["CONTENT_LENGTH"]在使用XmlHttpRequest上传文件时返回零

我在我的开发机器上遇到了一个问题,这台机器看起来很孤立,我无法弄明白.我有一个jQuery文件上传器,它将用户选择的文件发布到PHP脚本,以便使用XmlHttpRequest进行处理.该脚本在运行OSX10.6.3和MacAMP 1.9的MacBook Pro上工作正常,但是在我的iMac上使用完全相同的操作系统和MAMP版本,具有相同的服务器映像,它失败了.

我已经将错误的原因追溯到$_SERVER["CONTENT_LENGTH"]返回0, even though I can get the filename just fine and everything else seems to have succeeded about the request. For some reason it just won't seem to give me the actual content length. Here is the code that is causing the problem - the function in question is getSize().

class qqUploadedFileXhr {
    /**
     * Save the file to the specified path
     * @return boolean TRUE on success
     */
    function save($path) {    
        $input …
Run Code Online (Sandbox Code Playgroud)

php jquery xmlhttprequest

9
推荐指数
2
解决办法
8138
查看次数

Node.js - 使用XHR进行强大的上传

我尝试实现一个简单的XHR上传到Node.js(通过Formidable).问题是,如果我设置

xhr.setRequestHeader("Content-Type", "multipart/form-data");
Run Code Online (Sandbox Code Playgroud)

节点给我错误:

Error: bad content-type header, no multipart boundary
Run Code Online (Sandbox Code Playgroud)

如果我将边界设置为随机字符串没有任何反应.浏览器只挂起POST并等待服务器响应.

关键是如果我使用带有常规同步POST的强大功能,一切正常.

有人试图在XHR上传时使用Formidable吗?

xmlhttprequest node.js

9
推荐指数
1
解决办法
9313
查看次数

如何在Javascript中创建,合并和销毁xmlhttprequest对象

我的背景是传统的编译面向对象语言,如C++和.NET编程,我现在正在尝试一些新项目的JavaScript.我正在涉足AJAX,并且遇到了浏览器如何管理对象的令人困惑的方面.

[编辑#2] - 更改活动内容脚本

我有一个带有三个按钮的练习页面,每个按钮都更新一个<textarea>使用XMLHttpRequest对象:

  1. 按钮1使用slowtime.php中的文本内容更新TextArea1
  2. 按钮2使用slowtime.php中的文本内容更新TextArea2
  3. 按钮3使用fasttime.php中的文本内容更新TextArea3

slowtime.phpfasttime.php是简单的脚本与两个时间戳返回文本/ HTML页面:一个页面加载时,一个在一段时间后已经过去.

每次单击一个按钮时,每个按钮都能正常工作.如果在第一个请求完成之前单击按钮2然后单击按钮3,则更新仍可按预期工作.

如果在第一个请求完成之前单击按钮1然后单击按钮2,则TextArea1和TextArea2将接收正确的值; 然而,onreadystatechange事件调用同时发生,即第一个响应延迟,并且仅在第二个响应到达时处理.

示例代码

网站

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(url,target)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(target).value=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST",url,true);
xmlhttp.send();
}
</script>
</head>

<body>
<form>

<input type="button" value="Button 1" onClick="loadXMLDoc('slowtime.php','TextArea1')"/>
<input type="button" value="Button 2" onClick="loadXMLDoc('slowtime.php','TextArea2')"/>
<input type="button" value="Button 3" onClick="loadXMLDoc('fasttime.php','TextArea3')"/>

<div><textarea id="TextArea1"></textarea></div>
<div><textarea id="TextArea2"></textarea></div>
<div><textarea …
Run Code Online (Sandbox Code Playgroud)

html javascript ajax xmlhttprequest

9
推荐指数
1
解决办法
2063
查看次数

任何XMLHttpRequest完成后如何运行函数?

我正在开发一个项目,它有几个我无法改变的脚本.这些脚本通过AJAX更新页面.更新完成后,我需要运行一些代码.

任何XMLHttpRequest完成时是否会触发任何事件?(或任何XMLHttpRequest状态更改?).

不幸的是,我无法访问用于发出请求的特定XMLHttpRequest对象.

谢谢,

javascript ajax jquery xmlhttprequest

9
推荐指数
1
解决办法
9308
查看次数

基于XMLHttpRequest的基本身份验证的CORS调用在Firefox和Chrome中失败

需要使用javascript(在www.domain1.com)中使用Basic Auth进行REST GET调用.REST API位于domain2.com中.REST API返回CORS特定的HTTP标头.我需要支持IE,Chrome和Firefox.JavaScript下面进一步解释了这个问题 -

  1. 没有Basic Auth(IE 10中的WORKS,Chrome和Firefox,通过XDomainRequest对象处理旧的IE)

    var xhr = new XMLHttpRequest();
    xhr.open(method, url, true);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用Basic Auth(仅限IE 10中的WORKS,Chrome和Firefox中的失败)

    var xhr = new XMLHttpRequest();
    xhr.open(method, url, true, username, password);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用Basic Auth(在Chrome和Firefox中失败)

    var xhr = new XMLHttpRequest();
    xhr.open(method, url, true);
    xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
    xhr. withCredentials = “true”;
    
    Run Code Online (Sandbox Code Playgroud)
  4. 使用Basic Auth(在Chrome和Firefox中失败)

    $.ajax({
    type: 'GET',
    url: jsonp_url,
    dataType: "json",
    username: username,
    password: pwd,
    beforeSend: function (xhr) {xhr.withCredentials = true; },
    success: function (result) { },
    error: function …
    Run Code Online (Sandbox Code Playgroud)

jquery xmlhttprequest

9
推荐指数
1
解决办法
4810
查看次数

警告:在第0行的Unknown中,multipart/form-data POST数据中缺少边界

我正在处理文件上传器,当输入被更改时上传图像我的代码是html中的表单

<form method="post" enctype="multipart/form-data">
     <input name="uploaded[]" type="file" id="file_upload"/>
</form>
Run Code Online (Sandbox Code Playgroud)

我的JavaScript和Ajax:

        document.getElementById("file_upload").onchange = function() {
            var id = document.getElementById("user_id").innerHTML;
            var file = document.getElementById("file_upload").files[0];
            alert(file.size);
            var formdata = new FormData();
            formdata.append("filer",file,true);
            var ajax = new XMLHttpRequest();
            ajax.onreadystatechange =
            function(){
                if(ajax.readyState==4 && ajax.status==200){
                    document.getElementById("one").remove();
                    var img = document.createElement('img');
                    var first_path = '/user_image/';
                    var path = first_path.concat(id,'.png');
                    img.setAttribute('alt','User image');
                    img.setAttribute('id','one');                        
                    img.setAttribute('src',path);
                    document.getElementById("user").appendChild(img);  
                    alert("end");
                }    
                else{
                    document.getElementById("one").remove();
                    var img = document.createElement('img');
                    img.setAttribute('src','/img/loading.gif');
                    img.setAttribute('alt','User image');
                    img.setAttribute('id','one');
                    document.getElementById("user").appendChild(img);                        
                }
            }               
            ajax.open("POST","upload_image.php");
            ajax.setRequestHeader("Content-Type", "multipart/form-data");
            ajax.send(formdata);
        };
Run Code Online (Sandbox Code Playgroud)

而我的PHP代码很简单就是测试一切是否正常

require("../includes/config.php"); …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax html5 xmlhttprequest

9
推荐指数
1
解决办法
2万
查看次数

XHR仅进行一次射击

我正在尝试为文件上传创建进度条,但由于某种原因,XHR进度响应仅在结束时触发一次.但是,如果我打开了firebug窗口,它可以100%正常工作(在整个文件上传期间触发).我在localhost上测试它.

我的代码很长,但这是它的要点:

is_uploading = $.ajax({
  url: "/includes/upload.php?a=" + a_id,
  type: "POST",
  data: formdata,
  processData: false,
  contentType: false,
  dataType: "JSON",
  xhr: function () {
    var xhr = new window.XMLHttpRequest();
    xhr.upload.addEventListener("progress", function (evt) {
      alert('yay');//test to see if the event is firing...this should be alerting A LOT
      if (evt.lengthComputable) {
        //do stuff
      }
    }, false);

    return xhr;
  }

  ...more options here beforesend, success, etc
Run Code Online (Sandbox Code Playgroud)

过去几个小时我一直在拔头发,所以任何帮助都会受到赞赏.我不知道为什么它可以在firebug控制台打开的情况下工作,但如果它关闭则只会在最后点火......

javascript jquery xmlhttprequest

9
推荐指数
1
解决办法
1208
查看次数

使用jQuery文件上传上传一个超过1GB到2GB的大文件 - blueimp(基于Ajax)php/yii它在Firefox浏览器中显示错误

我正在尝试将大文件上传1GB2GB使用jQuery File Upload - blueimp(基于Ajax) php / yii Framework 1.15我已将这些值设置为上传更大的文件

memory_limit = 2048M
upload_max_filesize = 2048M 
post_max_size = 2048M 
Run Code Online (Sandbox Code Playgroud)

会话时间设置

ini_set('session.gc_maxlifetime', 7200);
Run Code Online (Sandbox Code Playgroud)

我测试的1GB文件比成功上传的文件要小

当我尝试上传大于1GB文件时,它会在50分钟上传时间后显示Forbidden错误...

服务器规格

  • 它是一个虚拟机,并且由于它不是生产尚未所以我们只用1CPU1GB memory,64位

文件上传工作中Google ChromeMicrosoft Edge(我曾与1.15和1.88 GB文件测试)时,我上传文件Mozilla Firefox小于300MB它成功上传,但是当我尝试哟一段时间了Ajax调用后上传超过300MB的文件更大的失败,给500 Internal Server Error 标题响应位于下图中 标头响应

php file-upload xmlhttprequest large-files jquery-file-upload

9
推荐指数
1
解决办法
1万
查看次数

Microsoft Edge:SCRIPT7002:XMLHttpRequest:网络错误0x2efd,由于错误00002efd无法完成操作

在Windows 10,Microsoft Edge上运行.我在IIS(10.119.103.10)的计算机上本地安装了一个应用程序,它试图向网络上的另一台机器(10.119.103.2)发出请求,该机器设置为使用CORS.

这一切都适用于chrome和Internet Explorer ......这是一个测试用例

function LOG(message) {
        var el = document.createElement('pre');
        el.textContent = message;
        output.appendChild(el);
}
function xhrtest(url) {
        var XHR = new XMLHttpRequest();
        LOG("OPEN " + url);
        XHR.open("GET", url, true);
        XHR.onreadystatechange = function(e) {
                LOG('READY ' + XHR.readyState + ' STATUS ' + XHR.status + ' ' + XHR.statusText + ' TYPE ' + XHR.responseType);
                LOG(XHR.response);
        }
        LOG("SEND");
        XHR.send();
}
Run Code Online (Sandbox Code Playgroud)
<button onclick="xhrtest('http://10.119.103.2/~adf/RMC2/trunk/server/?r=get')">XHR TEST</button>
<hr/>
<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)

但是,在Microsoft Edge中,我收到以下错误

SCRIPT7002:XMLHttpRequest:网络错误0x2efd,由于错误00002efd无法完成操作.

客户端(XMLHttpRequest)甚至没有尝试连接到服务器,它立即保释.生成此输出的测试用例: -

OPEN http://10.119.103.2/~adf/RMC2/trunk/server/?r=get 
SEND 
READY 4 STATUS …
Run Code Online (Sandbox Code Playgroud)

xmlhttprequest cors microsoft-edge

9
推荐指数
1
解决办法
1万
查看次数