Tag: xmlhttprequest

可以通过AJAX使用Google Maps / Places的“自动填充”API吗?

我正在尝试使用Google商家信息自动填充API在网络应用程序中使用企业数据预填充表单以简化数据输入。 API非常简单,但它似乎不想接受XHR。 $.getJSON(“https://maps.googleapis.com/maps/api/place/autocomplete/json”,{ input: input.term, sensor: false, types: ‘establishment’, location: ‘40.01496,-105.27029’, radius: 10000, key: Config.googleplaceskey },function(places_response){ //Some other code. }); 我在控制台中得到这个: XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/autocomplete/json?input=At&sensor=false&types=establishment&location=40.01496%2C-105.27029&radius=10000&key=AIzaSyDKzUgcLklQE_U5494vHq_SzrFakNHugaQ. Origin http://localhost:8086 is not allowed by Access-Control-Allow-Origin. 这在某种程度上不是API的意思吗? 任何人都知道一个变通方法,或者我可以发送一些额外的参数来使其工作? 更新: 以下是此调用的API文档的链接。 父文档实际上甚至还有JavaScript JSON解析示例。 真的很混淆为什么这会在服务器端关闭。 http://code.google.com/apis/maps/documentation/places/autocomplete.html

使用dropzone将其他数据发送到后端

我试图通过dropzone将一个特定的 – 已知的图像文件的位置ID发送到后端,该后端将被上传到服务器上。 虽然正在使用formData.append() ,但我看到没有附加任何内容。而只是这个“ FormData {} ”出现了。 dropzoneObject.on(“sending”, function(file, xhr, formData){ var nameOfFile = $(file.previewElement).find(“.dz-filename”).text(); var positionOfFile = fpos; //console.log(“The file who’s being sent is named: “+nameOfFile+” and its position id is: “+positionOfFile); formData.append(“fpos”, fpos); }); 我希望在例子中看到fpos = 16;

如何在任何XMLHttpRequest完成时运行一个函数?

我正在开发一个项目,它有几个我无法改变的脚本。 这些脚本通过AJAX更新页面。 更新完成后,我需要运行一些代码。 任何XMLHttpRequest完成后是否会触发任何事件? (或任何XMLHttpRequest状态更改?)。 不幸的是,我无法访问用于发出请求的特定XMLHttpRequest对象。 谢谢,

没有CORS或JSONP的跨域请求

我知道之前已经问过这个问题,但没有一个答案对我有用! 我正在做一个学校项目,我想得到学校服务器上动态调度文件返回的HTML(解析我的项目)。 我想要HTML的页面是: https : //telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched 我认为CORS没有为学校服务器文件启用,我不知道它是否支持JSONP … 如何设置跨域请求以从此页面获取HTML? 我试过了: $.ajax({ type:’POST’, url: ‘https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched’, headers: { ‘Access-Control-Allow-Origin’: ‘*’ }, contentType: ‘text/html’, crossDomain:true }).done(function( data ) { }); 我收到错误: XMLHttpRequest无法加载https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched 。 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许原点’null’访问。 响应具有HTTP状态代码501。 当我添加: dataType:’jsonp’ 我收到错误: 获取https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched?callback=jQuery21108736664191819727_1416964243449&_=1416964243450 400(错误请求)jquery.min.js:4send jquery.min.js:4n.extend.ajax jquery.min.js :4(匿名函数) 任何帮助是极大的赞赏!

使用XMLHttpRequest创建CORS Ajax请求

这是根据提供的示例validationgeoJSON的代码: 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 }); 我正在尝试使用以下代码validationgeoJSON : var getXHR=function() { try{return new XMLHttpRequest();} catch(e){} […]

如何从xhr.responseText获取“数据”字段?

我有下面给出的XMLHttpRequest()函数 var searchFriendRequests = function (userid) { var xhr = new XMLHttpRequest(); xhr.open(‘GET’, ‘http://localhost:6344/api/Registeration/searchFriendrequests?userid=’ + userid, false); xhr.setRequestHeader(“Content-Type”, “text/xml”); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { var data = xhr.responseText; } } }; xhr.send(null); } 其中xhr.responseText返回值为 { “$id”: “1”, “ContentEncoding”: null, “ContentType”: null, “Data”: [ { “$id”: […]

捕获javascript XMLHttpRequest的重定向位置

我知道在使用XMLHttpRequest时,你不能拦截重定向或阻止重定向,因为浏览器会透明地跟随它,但它是否可能 A.确定重定向的请求,或 B.确定重定向到的位置? (假设响应没有提示) 示例代码: $.post(“/my-url-that-redirects/”, {}, function(response, statusCode, xmlHttpRequest){ //Somehow grab the location it redirected to } ); 在我的情况下,firebug将首先显示对URL的POST,然后对重定向的URL进行GET。 可以捕获GET位置吗?

循环中的jQuery.ajax()

如果我在循环中调用jQuery.ajax() ,它会导致当前迭代中的调用覆盖最后一次调用还是为新请求分配了新的XHR对象? 我有一个循环来执行此操作,而从控制台日志我可以看到请求完成200 ok但是循环中最后一个请求的结果数据由请求success callback存储为假设。 代码: var Ajax = { pages: {}, current_request: null, prefetch: function () { currentPath = location.pathname.substr(1); if(this.pages[currentPath]) { var current = this.pages[currentPath]; delete this.pages[currentPath]; current[‘name’]=currentPath; current[‘title’]=$(“title”).text().replace(‘ – ‘.SITE_NAME, ”); current[‘meta_description’]=$(“meta[name=description]”).attr(‘content’); current[‘meta_keywords’]=$(“meta[name=keywords]”).attr(‘content’); } var _Ajax = this; //the loop in question ***** for(var key in this.pages) { $.ajax({ method: ‘get’, url:’http://’+location.hostname+’/’+key, […]

Ajax – Access-Control-Allow-Origin不允许使用Origin localhost

我对Ajax比较陌生,只是负责这个跨域调用。 我们的网页上有一个文本框,用户可以用它来预先搜索公司名称。 通过单击文本框旁边的按钮,将请求Ajax调用。 遗憾的是,Web服务位于一个单独的域中,因此这自然会导致问题。 以下是我做这项工作的最佳尝试。 我还应该注意,此调用的目的是以XML格式返回结果,该格式将在请求的success部分中进行解析。 这是错误消息: Origin http://localhost:55152 is not allowed by Access-Control-Allow-Origin. 我不知道如何处理解决方案,任何想法都会受到高度赞赏。 function GetProgramDetails() { var URL = “http://quahildy01/xRMDRMA02/xrmservices/2011/OrganizationData.svc/AccountSet?$select=AccountId,Name,neu_UniqueId&$filter=startswith(Name,\'” + $(‘.searchbox’).val() + “\’)”; var request = $.ajax({ type: ‘POST’, url: URL, contentType: “application/x-www-form-urlencoded”, crossDomain: true, dataType: XMLHttpRequest, success: function (data) { console.log(data); alert(data); }, error: function (data) { console.log(data); alert(“Unable to process […]

基本的AJAX请求获得“No’Access-Control-Allow-Origin’标头出现在请求的资源上”错误

我尝试向jQuery AJAX请求中的某个链接发送一个简单的GET请求。 这是一个非常简单的: $.ajax({ type: ‘GET’, url: /* */, dataType: ‘text/html’, success: function() { alert(“Success”); }, error: function() { alert(“Error”); }, }); 但是,无论我尝试过什么,我都得到XMLHttpRequest cannot load . No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:7776’ is therefore not allowed access. XMLHttpRequest cannot load . No ‘Access-Control-Allow-Origin’ header is present on the requested resource. […]