我的网站使用XMLHttpRequest(实际上是jQuery).我还有另一个站点在同一台服务器上运行,它提供一个脚本文件,使XHR请求返回到该站点,即.
http:// mysite:50000/index.html包含
<script src="http://mysite:9000/otherscript.js"></script>
Run Code Online (Sandbox Code Playgroud)
和http:// mysite:9000/otherscript.js包括
$.ajax({
url: 'http://mysite:9000/ajax/stuff'
});
Run Code Online (Sandbox Code Playgroud)
问题是 - 这不起作用.来自加载脚本的AJAX请求失败,没有错误消息.从我能够发现的这是旧的同源政策.鉴于我控制了两个站点,我能做些什么才能使这项工作成功?"document.domain"技巧似乎没有为XMLHttpRequest做任何事情.
我正在写使用的PhoneGap(又名科尔多瓦)iOS应用程序,我有一个登录使用一个XMLHttpRequest通过SSL基本身份验证的用户一个简单的HTML登录页面.当您正确输入用户名和密码时,一切都运作良好.但是,如果输入错误的用户名/密码,则不会调用任何回调.
例如,如果您在Chrome上运行相同的代码,使用错误的用户名/密码,则Chrome会以类似的方式运行,但会弹出身份验证质询对话框.在chrome的对话框上点击取消会将控制权返回给我的javascript代码.不幸的是,在iOS上,UIWebView甚至不会弹出一个auth对话框,它只是挂起.我需要一种方法告诉用户他们输入了错误的用户名或密码,以便他们可以重试.
最接近的一个答案,我能找到的这个http://www.freelock.com/2008/06/technical-note-http-auth-with-ajax但是从服务器更改响应状态似乎并不像正确的事情.
这基本上是我的请求代码的样子,但是当发送一个错误的用户名或密码时,它永远不会到达我的onload回调(实际上onreadystatechange回调只被调用一次,那就是readyState 1,也就是OPEN).
var req = new XMLHttpRequest();
req.onload = function(ev) {
if (req.status == 401) {
alert("Invalid Username/Password");
document.getElementById('password').focus();
} else if (req.status == 200) {
window.location.href = some_secure_site;
} else {
// edit //
alert("Some other status");
}
}
req.onerror = function (ev) { alert('Error'); };
req.ontimeout = function(ev) { alert('Timeout'); };
req.open('GET', uri, true, userValue, passValue);
req.withCredentials = true;
req.send();
Run Code Online (Sandbox Code Playgroud) 我有来自KSOAP2库的HttpTransportSE对象.我想转储响应文件,其中可能包含mote然后简单的9697字符.目前我正在做运输.
transport.debug = true;
System.out.println("Response ----------"+transport.responseDump);
Run Code Online (Sandbox Code Playgroud)
但它给了我一半的反应......最后.
在其内部编码结构中,我发现它使用256个字节来创建和销毁它的responseDump,如下所示:
package org.ksoap2.transport;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.util.List;
import org.ksoap2.HeaderProperty;
import org.ksoap2.SoapEnvelope;
import org.xmlpull.v1.XmlPullParserException;
public class HttpTransportSE extends Transport
{
private ServiceConnection connection;
public HttpTransportSE(String url)
{
super(null, url);
}
public HttpTransportSE(Proxy proxy, String url)
{
super(proxy, url);
}
public HttpTransportSE(String url, int timeout)
{
super(url, timeout);
}
public HttpTransportSE(Proxy proxy, String url, int …Run Code Online (Sandbox Code Playgroud) 这是根据提供的示例验证geoJSON的代码:
function processSuccess(data){
if(data.status==="ok") console.log("You just posted some valid geoJSON");
else if(data.status==="error") console.log("There was a problem with your geoJSON "+data.message);
}
function processError(data){
console.log("The AJAX request could not be successfully made");
}
$.ajax({
url: 'http://geojsonlint.com/validate',
type: 'POST',
data: geo,
dataType: 'json',
success: processSuccess,
error: processError
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试geoJSON使用以下代码进行验证:
var getXHR=function()
{
try{return new XMLHttpRequest();} catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP.6.0");} catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP.3.0");} catch(e){}
try{return new ActiveXObject("Microsoft.XMLHttp");} catch(e){}
console.err("Could not find XMLHttpRequest");
};
var makeRequest=function(uri,data)
{
//make the actual XMLHttpRequest …Run Code Online (Sandbox Code Playgroud) 我正在寻找一些方法来优雅地检查IE8中的XmlHttpRequests.我不介意插件或外部程序.我还没有发现任何与Firebug一样好的东西.
我已经尝试过Julien Couvreur的书签调试器,但它似乎与Prototype不兼容.朱利安的剧本
javascript ajax xmlhttprequest internet-explorer-8 ie-developer-tools
每当我使用以下代码时,网络服务器(运行IIS 7)拒绝向我发送内容,而是发送"400 Bad Request".
request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
Run Code Online (Sandbox Code Playgroud) 我在我的开发机器上遇到了一个问题,这台机器看起来很孤立,我无法弄明白.我有一个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) 我尝试实现一个简单的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吗?
我正在尝试为文件上传创建进度条,但由于某种原因,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控制台打开的情况下工作,但如果它关闭则只会在最后点火......
我有一个完整的组件混乱.现在我传递了一个功能,我一直在尝试一百万件我无法工作的东西.
export default class DatafileUpload extends Component {
initialState = {
fileUploading: false,
fileList: [],
status: 'empty', // 'empty' | 'active' | 'success' | 'exception'
file: {}
}
state = this.initialState
static propTypes = {
userId: PropTypes.string.isRequired,
datasetId: PropTypes.string.isRequired
}
scrubFilename = (filename) => filename.replace(/[^\w\d_\-.]+/ig, '')
requestSignedS3Url = (file) => {
const filename = this.scrubFilename(file.name)
const params = {
userId: this.props.userId,
contentType: file.type,
Key: `${filename}`
};
return api.get('/s3/signUpload', { params })
.then(response => {
return response.data;
})
.catch(error => { …Run Code Online (Sandbox Code Playgroud) xmlhttprequest ×10
javascript ×6
ajax ×3
jquery ×3
android ×1
antd ×1
cordova ×1
cors ×1
cross-domain ×1
iis-7 ×1
ios ×1
node.js ×1
php ×1
reactjs ×1
xml ×1
xml-parsing ×1