Tag: xmlhttprequest

来自jquery或XMLHttpRequest的HTTP GET到amazon aws失败,Access-Control-Allow-Origin不允许使用Origin

从jQuery或XMLHttpRequest获取amazon AWS安全令牌运气不佳。 当我从jQuery或XmlHttpRequest发送HTTP GET时,我得到“Origin http:// Access-Control-Allow-Origin不允许MY_IP。”但是如果我在浏览器中粘贴相同的URL,那一切都很顺利。 我的代码: var url_ = “https://sts.amazonaws.com/?Action=GetSessionToken” + “&DurationSeconds=3600” + “&AWSAccessKeyId=” + AccessKeyId + “&Version=2011-06-15” + “&Timestamp=” + encode(timestamp) + “&Signature=” + encode(hash) + “&SignatureVersion=2&SignatureMethod=HmacSHA256”; $.get(url_, function(data) { alert(“response: “+data); }); 我的标题: 响应标题 Accept-Ranges字节 年龄198岁 连接保持活跃 内容长度3739 内容类型文本/ html 日期星期一,2012年6月25日17:48:20 GMT Etag“48c4862-e9b-4c34f76b13400” Last-Modified Mon,25 Jun 2012 17:39:28 GMT 代理连接保持活跃 服务器Apache / […]

Javascript:从XMLHttpRequest读取原始字节 – 搞砸了

我正在使用这个原始问题的代码片段: 使用JavaScript从二进制文件中读取字节,而不使用jQuery 但是,由于某些原因,似乎加载了一整套不同的字节! 我怀疑这与字符串转换有关。 这是我试图下载的二进制文件的副本: http : //steeman.dk/html5/coco/colorbasic13.rom 对于我的本地IIS 7.5服务器,我已将.rom MIME类型添加为“application / octet-stream”(我还尝试使用’text / plain; charset = x-user-defined’,结果相同)。 我期待的是从这开始的字节序列: a1 cb a2 82 a7 7c a7 0b a7 f4 a9 de a7 d8 10 ce (etc.) 但是,我得到的是以下内容: fd e2 fd fd 7c fd 0b fd fd fd a7 fd 10 fd 03 c6 37 fd […]

jQuery.ajax()调用返回JSON.parse意外字符错误

我正在尝试调试以下jQuery.ajax()调用: var rollnum = $(‘#rollNum’).val() $.ajax({ url: sURL + “myController/myMethod”, type: “POST”, data: {rollnum: rollnum}, dataType: ‘json’, success: function(json){alert(json)}, error:function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(thrownError);} }); 这是方法: function myMethod(){ $query = $this->db->query(“SELECT tblontario.Address, tblontario.Municipality FROM tblontario WHERE RollNum = 211010002528200”); $json_address = array(); $json_municipality = array(); foreach ($query->result_array() as $row){ $json_address[] = $row[‘Address’]; $json_municipality[] = […]

无法从youtube通过json提取video

有时我在json提取youtubevideo时遇到此错误,这是一个例子: XMLHttpRequest无法加载https://gdata.youtube.com/feeds/api/users/IcarusTouma?&alt=json 。 Access-Control-Allow-Origin不允许使用origin http:// localhost 。 我尝试使用jsonp,但youtube不接受jsonp。 从youtube中提取video。 $. getJSON (‘https://gdata.youtube.com/feeds/api/videos/’ + id_video + ‘? & alt = json’, function (data) { if (typeof data! == “undefined” && data) { var title = data [‘entry’] [‘title’] [‘$ t’]; var thumb = data [‘entry’] [‘media $ group’] [‘media $ thumbnail’] [0] [‘url’]; var title = […]

onReadyStateChange未在IE中为XHR请求触发

我有这个代码,我正在使用它在chrome中工作正常,但在IE中,看起来onreadystatechenge没有触发。 如何让它跨浏览器工作。 我在IE中读到你必须在发送之前放置onreadystatechange事件,但这不起作用。 此处的警报未触发。 是的,它是成功的。 if (xhr.status==200 && xhr.readyState==4) { alert(“DONE!”); } 这是整个请求。 function SendFile(evt) { var xhr = new XMLHttpRequest(); var data = new FormData(); var files = $(“#FileUpload1”).get(0).files; for (var i = 0; i < files.length; i++) { data.append(files[i].name, files[i]); } xhr.upload.addEventListener("progress", function (evt) { if (evt.lengthComputable) { var progress = Math.round(evt.loaded * […]

Javascriptfunction是否因浏览器而异?

我想知道一些关于Javascript的事情。 Javascriptfunction或行为是否会因浏览器而改变? 当我使用Javascript XMLHttpRequest upload方法时,我注意到Internet Explorer发送小字节但Firefox和Google Chrome发送大字节。 因此,当我使用Firefox或Chrome发送大数据时,服务器正在提供OutOfMemoryexception。 我正在编辑带有图像细节的post。

XMLHttpRequest跨域抛出错误

我为注册使用的网站的顶级网站制作了“投票”API。 var id = 1; $(document).ready(function(){ $.getJSON(“http://mysite.com/index.php?page=vote”, { id: id, hasVoted: ‘unknown’ }, function(data) { if(data == 2) { window.location.replace(“http://mysite.com/index.php?page=vote&id=” + id); } }); }); 基本上,我给用户他们的ID,然后他们把那些代码放在他们的文件中。 该网站返回一个数字,然后,它重定向用户或不重新投票。 因此,在localhost上测试代码会抛出此错误: XMLHttpRequest cannot load http://mysite.com/index.php?page=vote&id=1&hasVoted=unknown. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 如果我使用此代码: var id = 1; $(document).ready(function(){ $.getJSON(“http://mysite.com/index.php?page=vote&callback=?”, { id: id, hasVoted: ‘unknown’ }, function(data) { if(data […]

Node.js发送后无法设置标头。 在另一个XHR请求中启动XHR请求时

Node.js无法处理我的客户端代码,它执行类似于jQuery / Zepto XHR模式的内容: $.ajax({ type: ‘POST’, url: ‘/someUrl’, success: function(response) { $.ajax({ // … do another XHR 我已经在其他框架中完成了这个(在另一个XHR请求中发起XHR请求)模式。 我读过有关Node.js错误:无法在发送标头后设置标头以及Node.js服务器的基于事件的模型如何工作。 换句话说,第一个XHR请求没有调用res.end()所以当第二个XHR请求被调用时Node.js会抱怨(在一个连续的循环btw中)。 我的问题是:是否有人能够推荐一种替代模式来链接客户端的XHR请求? 有什么东西我可以做Node.js服务器端来保持现有的客户端模式? 根据接受的答案更新 错误肯定在我自己的服务器端代码中。 一个简单的validation函数抛出一个错误,但在捕获它时,只调用了res.end()。 出于某种原因我假设调用res.end()会立即停止执行该函数。 在这种情况下,插入“return”会在将JSON消息发送到客户端后立即停止执行。 if (_.isEmpty(req.body)) { res.end(JSON.stringify({‘Error’:’POST required’})); // suppose ‘return’ is needed here as well return } else { try { if (_.has(req.body, ‘id’)) { id = parseInt(req.body[‘id’]); } […]

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

我已经看过关于此的大部分post,但我似乎无法找到正确的解决方案。 我有2个Solution,Bioman和PowerRangers,都有一个代码模块,一个javascript获取触发器下拉列表更改加载一个表(如下图所示) BIOMAN使用Ajax在CodesController上使用Index Action获取数据 function ajaxCall(obj) { var retdata = {}; $.ajax({ dataType: “json”, type: “POST”, contentType: ‘application/json; charset=utf-8’, data: JSON.stringify(obj), async: false, processData: false, cache: false, success: function (data) { retdata = data; }, error: function (xhr) { alert(“error”); } }); return retdata; } 然后调用javascript来加载表 function drawCodesTable(codes) { var sHTML = []; if (codes […]

在jQuery v1.x中从$ .ajax承诺中捕获403

我在jQuery v1.x中从$.ajax承诺中捕获403时遇到问题。 相同的代码 $.ajax({ dataType: ‘jsonp’, url: ‘http://www.checkupdown.com/accounts/grpb/B1394343/’, type: ‘GET’ }).then(function () { console.log(‘success’, arguments) }, function () { console.log(‘error’, arguments) }); 拒绝jQuery v2.x中的预期,但在jQuery v1.x中没有任何记录(promise有readyState == 1 )。 这些示例分别使用2.1.3和1.11.3 jQuery版本。 为什么会发生这种情况呢? 它是否可以解决jQuery v1?