Tag: 请求

通过按钮点击事件取消当前的ajax请求!

如果我的ajax请求花费很长时间连接速度较慢,我想取消。 我在.ajaxStart()时显示一个叠加层,如果超过五个secons(我使用setInterval管理),则会在叠加层上显示一个按钮,该按钮将取消当前的ajax请求。 inheritance了我的一些代码: jqXHR = $.ajax({ url: ‘includes/inc_ajax.php’, type: ‘POST’, data: ‘&ajax=1&action=7’, success: function (txt) { var cntr = $.parseJSON(txt); $(“#onlineppl”).html(cntr.online); $(“#todayppl”).html(cntr.bugun); $(“#totalppl”).html(cntr.toplam); } }); $(“#abortAjax”).button({ icons: {secondary: “ui-icon-cancel”} }).click(function() { $(jqXHR).abort(); }); 我是否必须将$.ajax()函数分配给变量才能中止它? 我也有很多由ajax调用的ajax请求,所以我猜浏览器无法跟踪导致中止方法无法工作的相同var名称。 这是我的第一个问题,我有点困惑。 任何帮助赞赏。 谢谢。

请求URI太大(414)

我通过$.getJSON发送GET请求,发送的数据非常大。 我需要在处理完数据后得到一个结果,所以POST它似乎不是一个解决方案。 任何的想法? 发送的数据是一个编码为json的字符串。 我考虑先发送它而不先编码,作为一个数组,但后来我的响应只是“数组”,所以之后无法解码它。

我可以使用JavaScript / JQuery将上传的文件添加到ASP.NET中的Request.Files吗?

我不完全确定如何使用JavaScript将文件添加到Request.Files中? 这就是我想要的…… var x = $(‘input[type=file]:eq(0)’); //Add the data to the hidden field hiddenField.val(x.val()); //Add the html display fileDisplayDiv.innerHTML += “display name”; //Add this file to request.files How to do??? //Clear the input so the user may add more files before postback. x.val(“”); 输入是常规HTML输入。 是的,最终我正在尝试开发一个多文件上传(这就是我清除输入字段的原因) – 我看了第三方的东西,但我需要自定义function来处理我正在做的事情。 我认为这个任务似乎应该是可能的,否则ajax上传器将如何工作? 任何帮助表示感谢,提前谢谢。

内容加载上的html + Ajax + jquery +预定义主题(Inspinia)插件

我有一些不便,我是一名新的网络程序员,我正在冒险进入标题中描述的这个主题。 我正在使用基于HTML + Jquery + Boottrap的主题和带有默认主题的其他插件。 这种情况有点困难,因为据我所知,我正在尝试实施Ajax来管理内容。 问题是,并非一切都运行良好,我有一些错误,特别是当我向DOM添加HTML内容并认为它可能是方式或我编写我的JavaScript。 我希望有人能见到他并给我一些议会。 引用主要问题。 1.例如,datepicker将其翻译为西class牙语,但我收到错误(语言)。 2.另一个问题是每个插件的重新初始化,你看到内容的变化,这是必要的还是有更好的方法。 添加内容 $(‘[id^=”p-“]’).on(“click”, function (event, xhr, settings) { var id = event.target.id; $.ajax( {type:”GET”,url:”index.php”,data:{idform:id}, error: function(xhr,status,error){alert(error);}, success: function(response) {$(“#formarea”).html(response);$(“#formarea”).attr(‘name’, id); window.ChargeJS(); CallProcces();// carga la llamada de procesos } }); $.ajax( {type:”GET”,url:”index.php”,data:{idfield:id}, error: function(xhr,status,error){alert(error);}, success: function(data) {$(“#areatitle”).html(data);} }); }); 在内容加载时重新启动批量插件 function LoadJSfile(){ /* La carga […]

跨域ajax请求返回XML:Access-Control-Allow-Origin不允许使用Origin http:// …

这是一个不适合我的jQuery: $.ajax({ crossDomain: true, type: “POST”, url: “https://www.testdatasolutions.com/reportgw”, data: “ACCOUNT=creditreport123&PASSWD=asdj97sdf&PASS=2&PROCESS=PCCREDIT&NAME=Robert+Ice&SSN=891-42-3221&ADDRESS=111+W+8th+St&CITY=Fantasy+Island&STATE=IL&ZIP=60750&BUREAU=TU&PRODUCT=CREDIT&DEFAULTOUTPUT=XML” }) .done(function( msg ) { alert( “Data Saved: ” + msg ); }); 输出错误说: XMLHttpRequest无法加载https://www.testdatasolutions.com/reportgw 。 Access-Control-Allow-Origin不允许来源http://pmr.techforge.us 。 可以在此处找到类似的主题,但它仅涵盖输出为JSON的情况。 所以我的问题是,是否可以处理返回XML的跨域ajax请求,或者我绝对必须使用JSONP ?

很多时候401“未经授权。”对ajax请求

我的一个应用程序页面是通过我的页面中的ajax加载一些内容(目前有两个请求,文档就绪后)。 很多次我收到这个ajax请求状态“401”,响应“未授权”。 有时刷新页面(使用F5)是否正常工作,有时候一个请求正在接收401状态。 而且我收到500的次数较少(在这种情况下,laravel使用错误的数据库凭据,而不是来自.env)。 任何人都可以帮我解决这个问题吗? 使用Laravel 5.1.6 谢谢 public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($request->ajax()) { return response(‘Unauthorized.’, 401); } else { return redirect()->guest(‘auth/login’); } } return $next($request); }

如何从jQuery ajax调用获得响应时间?

所以我正在研究可以显示页面请求的工具。 我通过使用jQuery Ajax(http://api.jquery.com/jQuery.ajax/)来做这件事,我想弄清楚获得响应时间的最佳方法。 我发现了一个线程(http://forum.jquery.com/topic/jquery-get-time-of-ajax-post),它描述了在JavaScript中使用“Date”,但这种方法真的可靠吗? 我的代码示例如下 $.ajax({ type: “POST”, url: “some.php”, }).done(function () { // Here I want to get the how long it took to load some.php and use it further });

jQuery JSON请求获得’200 OK’答案,但没有内容

我正在使用jQuery通过他们的IP地址获取访问者的位置。 这个名为freeGeoIP的服务很棒 。 我需要做的就是在URL末尾添加’json’或’xml’,然后添加IP地址,它将返回所需的数据。 当我在浏览器中手动执行此操作时,它可以正常工作:我需要下载一个小文档。 当我从浏览器执行$ .ajax或$ .getJSON请求时,它会回答“200 OK”标题和下面的元数据。 但是没有实际数据进来。发生了什么? 编辑:我添加了javascript / jQuery代码: function openForm(event,ui){ var _this = $(this); //Get details on the user’s IP var myIP = $(‘#yourIP’).attr(‘ip’);alert(myIP); var url = ‘http://freegeoip.appspot.com/json/’ + myIP; $.ajax({ url: url, dataType: ‘json’, contentType: ‘text/json’, timeout: 10000, complete: function(ip){ alert(‘Success Ajax!’); //URL returns status,ip,countrycode,countryname,regioncode,regionname,city,zipcode,latitude,longitude $(‘#yourIP’).text(ip.city + “, ” […]

如何在zend框架2或AjaxContext中使用ajax?

AjaxContext助手在ZF1中是一个很好的function,我在很多地方使用它。 我想知道这是否在ZF2中可用。 我做了一个测试,并补充说: public function init() { $ajaxContext = $this->_helper->getHelper(‘AjaxContext’); $ajaxContext->addActionContext(‘input’, ‘html’) ->addActionContext(‘number’, ‘html’) ->initContext(); } 在控制器中,添加了一个动作: public function inputAction() { $form = new AddInput(); return [‘form’ => $form]; } 文件input.ajax.phtml 和ajax调用: $.get(‘/form/input/format/html’).css(“display”,”block”); 请求通过ok,使用200代码,但我得到渲染错误 Fatal error: Uncaught exception ‘Zend\View\Exception\RuntimeException’ with message ‘Zend\View\Renderer\PhpRenderer::render: Unable to render template “form/index/input”; resolver could not resolve to a file’ in […]

Javascript,同时jQuery多个AJAX请求

function makeCall(file, handlerFile, sendMethod, formData) { //console.log(instance.files); $.ajax({ url: handlerFile, type: sendMethod, xhr: function() { // Custom XMLHttpRequest var xhr = $.ajaxSettings.xhr(); if(xhr.upload) { // Check if upload property exists xhr.upload.addEventListener(‘progress’, progressHandlingFunction.bind(file)); // For handling the progress of the upload //xhr.upload.addEventListener(‘loadend’, successHandler.bind(xhr)); } //console.log(xhr); return xhr; }, beforeSend: beforeSendHandler.bind(file), success: completeHandler.bind(file), //error: errorHandler, data: formData, […]