我想检查页面是否返回状态代码401.这可能吗?
这是我的尝试,但它只返回0.
$.ajax({
url: "http://my-ip/test/test.php",
data: {},
complete: function(xhr, statusText){
alert(xhr.status);
}
});
Run Code Online (Sandbox Code Playgroud) ajax jquery xmlhttprequest http-status-codes http-status-code-401
POST是否足够安全以发送登录凭据?
或者是必须的SSL连接?
我正在尝试开发一个侧边栏小工具,它可以自动检查网页以确保我的转移配额的演变过程.我差不多了,但还有最后一步我需要让它工作:将带有正确POST数据的HttpRequest发送到php页面.使用firefox插件,标题的"Content-Type"如下所示:
Content-Type=multipart/form-data; boundary=---------------------------99614912995
Run Code Online (Sandbox Code Playgroud)
参数"boundary"似乎是随机的,POSTDATA是这样的:
POSTDATA =-----------------------------99614912995
Content-Disposition: form-data; name="SOMENAME"
Formulaire de Quota
-----------------------------99614912995
Content-Disposition: form-data; name="OTHERNAME"
SOMEDATA
-----------------------------99614912995--
Run Code Online (Sandbox Code Playgroud)
我不明白如何正确模拟POSTDATA与神秘的"边界"参数回来.
有人知道我怎么能解决这个问题吗?
我有一个React组件,我想从文件中加载我的JSON数据.控制台日志当前不起作用,即使我将变量数据创建为全局变量
'use strict';
var React = require('react/addons');
// load in JSON data from file
var data;
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "data.json", true);
oReq.send();
function reqListener(e) {
data = JSON.parse(this.responseText);
}
console.log(data);
var List = React.createClass({
getInitialState: function() {
return {data: this.props.data};
},
render: function() {
var listItems = this.state.data.map(function(item) {
var eachItem = item.works.work;
var photo = eachItem.map(function(url) {
return (
<td>{url.urls}</td>
)
});
});
return <ul>{listItems}</ul>
}
});
var redBubble = React.createClass({ …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.open("GET", "//URL")
xhr.setRequestHeader("Content-Type: application/json", "Authorization: Basic //AuthKey");
xhr.send();
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Cannot find module 'xmlhttprequest'
Run Code Online (Sandbox Code Playgroud)
当我删除第一行时,我得到:
XMLHttpRequest is not defined
Run Code Online (Sandbox Code Playgroud)
我已经搜遍过各地,人们已经提到Node.js的问题,但我的Node安装是正确的,所以我不确定是什么问题.
当我使用XMLHttpRequest时,使用正确上传文件FormData.但是,当我切换到时jQuery.ajax,我的代码中断了.
这是工作原始代码:
function uploadFile(blobFile, fileName) {
var fd = new FormData();
fd.append("fileToUpload", blobFile);
var xhr = new XMLHttpRequest();
xhr.open("POST", "upload.php", true);
xhr.send(fd);
}
Run Code Online (Sandbox Code Playgroud)
这是我不成功的jQuery.ajax尝试:
function uploadFile(blobFile, fileName) {
var fd = new FormData();
fd.append("fileToUpload", blobFile);
var xm = $.ajax({
url: "upload.php",
type: "POST",
data: fd,
});
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?如何使用AJAX正确上传文件?
嗨,我正在尝试使用此代码发送带有xmlhttprequest的文件.
<script>
var url= "http://localhost:80/....";
$(document).ready(function(){
document.getElementById('upload').addEventListener('change', function(e) {
var file = this.files[0];
var xhr = new XMLHttpRequest();
xhr.file = file; // not necessary if you create scopes like this
xhr.addEventListener('progress', function(e) {
var done = e.position || e.loaded, total = e.totalSize || e.total;
console.log('xhr progress: ' + (Math.floor(done/total*1000)/10) + '%');
}, false);
if ( xhr.upload ) {
xhr.upload.onprogress = function(e) {
var done = e.position || e.loaded, total = e.totalSize || e.total;
console.log('xhr.upload progress: ' + done + ' …Run Code Online (Sandbox Code Playgroud) 是否可以在JavaScript中仅使用XMLHTTPRequest来执行HTTP头请求?
我的动机是节省带宽.
如果没有,是否有可能伪造它?
我总是想知道为什么这个对象会被这样调用?
您的请求正文不需要是XML格式.此外,从服务器接收的数据可以作为JSON,XML,HTML或纯文本提取.XML在此对象中不起重要作用.这有点陈词滥调吗?这个对象在第一次创建时曾经是什么?
我正在尝试实现文件上传API,这里给出:
Mediafire文件上传
我能成功上传后的数据和获取数据,但不知道如何发送X-文件名的属性,这是为了将头数据作为API指南中给出.
我的代码:
xmlhttp=new XMLHttpRequest();
var formData = new FormData();
formData.append("Filedata", document.getElementById("myFile").files[0]);
var photoId = getCookie("user");
// formData.append("x-filename", photoId); //tried this but doesn't work
// xmlhttp.setRequestHeader("x-filename", photoId); //tried this too (gives error) [edited after diodeous' answer]
xmlhttp.onreadystatechange=function()
{
alert("xhr status : "+xmlhttp.readyState);
}
var url = "http://www.mediafire.com/api/upload/upload.php?"+"session_token="+getCookie("mSession")+"&action_on_duplicate=keep";
xmlhttp.open("POST", url);
// xmlhttp.setRequestHeader("x-filename", photoId); //tried this too, doesnt work. Infact nothing gets uploaded on mediafire. [edited after apsillers' answer]
// cant get response …Run Code Online (Sandbox Code Playgroud) xmlhttprequest ×10
javascript ×7
ajax ×6
jquery ×3
file-upload ×2
http-headers ×2
form-data ×1
http ×1
json ×1
mediafire ×1
mime-types ×1
node.js ×1
post ×1
reactjs ×1
security ×1