pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='5sYKz'></bdo><ul id='5sYKz'></ul>

<small id='5sYKz'></small><noframes id='5sYKz'>

  • <i id='5sYKz'><tr id='5sYKz'><dt id='5sYKz'><q id='5sYKz'><span id='5sYKz'><b id='5sYKz'><form id='5sYKz'><ins id='5sYKz'></ins><ul id='5sYKz'></ul><sub id='5sYKz'></sub></form><legend id='5sYKz'></legend><bdo id='5sYKz'><pre id='5sYKz'><center id='5sYKz'></center></pre></bdo></b><th id='5sYKz'></th></span></q></dt></tr></i><div class="55fl7jj" id='5sYKz'><tfoot id='5sYKz'></tfoot><dl id='5sYKz'><fieldset id='5sYKz'></fieldset></dl></div>

    <tfoot id='5sYKz'></tfoot>
    1. <legend id='5sYKz'><style id='5sYKz'><dir id='5sYKz'><q id='5sYKz'></q></dir></style></legend>

      1. JavaScript Ajax 請求 vs jQuery $.ajax

        JavaScript Ajax request vs jQuery $.ajax(JavaScript Ajax 請求 vs jQuery $.ajax)
          <bdo id='c2mNQ'></bdo><ul id='c2mNQ'></ul>
          <tfoot id='c2mNQ'></tfoot>

          1. <legend id='c2mNQ'><style id='c2mNQ'><dir id='c2mNQ'><q id='c2mNQ'></q></dir></style></legend>

            <i id='c2mNQ'><tr id='c2mNQ'><dt id='c2mNQ'><q id='c2mNQ'><span id='c2mNQ'><b id='c2mNQ'><form id='c2mNQ'><ins id='c2mNQ'></ins><ul id='c2mNQ'></ul><sub id='c2mNQ'></sub></form><legend id='c2mNQ'></legend><bdo id='c2mNQ'><pre id='c2mNQ'><center id='c2mNQ'></center></pre></bdo></b><th id='c2mNQ'></th></span></q></dt></tr></i><div class="vhpx7tl" id='c2mNQ'><tfoot id='c2mNQ'></tfoot><dl id='c2mNQ'><fieldset id='c2mNQ'></fieldset></dl></div>

                  <tbody id='c2mNQ'></tbody>

                • <small id='c2mNQ'></small><noframes id='c2mNQ'>

                  本文介紹了JavaScript Ajax 請求 vs jQuery $.ajax的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  注意:我粘貼了比 ajax 調用更多的代碼,以防代碼是(部分)導致問題的原因.但是,我不認為是這樣,因此您最好將注意力集中在 ajaxjAjax 函數上.
                  另請注意,由于對此問題的評論(帶有贊成票)說我的代碼難以破譯,我很樂意澄清需要澄清的內容,如果這可以證明是找到問題的關鍵.
                  謝謝.

                  NOTE: I've pasted more code than just the ajax calls, on the off chance that code is (part of) what's causing the problem. I don't think it is, however, so you're probably better off focussing on the ajax and jAjax functions a bit further down.
                  Also note that, since there's a comment (with upvote) on this question saying my code is hard to decipher, I'd happily clarify what needs clarifying if that could prove to be the key in finding the problem.
                  Thanks.

                  事情就是這樣.我正在嘗試放棄 jQuery,因為我唯一使用的是 $.ajax() 方法,并且包括像 jQuery 這樣的整個庫僅用于 1 個功能是 IMO 瘋狂的.我什至不需要 $.ajax 方法的全部功能,因此我編寫了自己的 ajax 函數.

                  Here's the thing. I'm trying to ditch jQuery, since the only thing I use is the $.ajax() method, and including an entire lib like jQuery for just 1 feature is IMO crazy. I don't even need the full functionality of the $.ajax method anyway, hence I wrote my own ajax function.

                  問題是:它不起作用,我似乎無法弄清楚原因.我正在嘗試將對象發送到服務器(特別是:控制器中的 ajaxAction - 使用 Zend FW).下面是 javascript 代碼,以及 firebug 控制臺告訴我的內容的摘要.

                  The problem is: it's not working, and I can't seem to figure out why. I'm trying to send objects to the server (specifically: ajaxAction in the controller - using Zend FW). Below is the javascript code, and a summary of what the firebug console tells me.

                  if (!String.prototype.trim)
                  {
                      String.prototype.trim = function()
                      {
                          "use strict";
                          return this.replace(/^ss*/, '').replace(/ss*$/, '');
                      };
                  }
                  
                  function getUrl(action,controller)
                  {
                      var base,uri;
                      base = window.location.href.replace('http://'+window.location.host,'');
                      if (base.length > 1)
                      {
                          base = base.substring(1,base.length).split('/');
                          controller = controller || base[0];
                          base[0] = controller || base[0];
                          base[1] = action || base[1];
                          return '/'+base.join('/');
                      }
                      controller = controller || 'index';
                      action = action || 'ajax';
                      return base+controller+'/'+action;
                  }
                  
                  function formalizeObject(obj,recursion)
                  {
                      recursion = recursion || false;
                      if (typeof obj !== 'object')
                      {
                          throw new Error('no object provided');
                      }
                      var ret = '';
                      for (var i in obj)
                      {
                          if (!obj.hasOwnProperty(i) || typeof obj[i] === 'function')
                          {
                              continue;
                          }
                          if (recursion)
                          {
                              ret +='['+i+']';
                          }
                          else
                          {
                              ret += (ret.length > 0 ? '&' : '') + i.toString(); 
                          }
                          if (typeof obj[i] === 'object')
                          {
                              ret += formalizeObject(obj[i],true);
                              continue;
                          }
                          ret += '='+obj[i].toString();
                      }
                      if (recursion)
                      {
                          return ret;
                      }
                      return encodeURI(ret);
                  }
                  
                  function success()
                  {
                      if (this.readyState===4 && this.status===200)
                      {
                          console.log(this.responseText);
                      }
                  }
                  
                  function ajax(str,url,method,json)
                  {
                      var ret;
                      json = json || false;
                      str = str || {};
                      method = method || 'POST';
                      url = url || getUrl();
                      str = 
                      str = (typeof str === 'object' ? str : {data:str});
                      try
                      {
                          ret = new XMLHttpRequest();
                      }
                      catch (error)
                      {
                          try
                          {
                              ret= new ActiveXObject('Msxml2.XMLHTTP');
                          }
                          catch(error)
                          {
                              try
                              {
                                  ret= new ActiveXObject('Microsoft.XMLHTTP');
                              }
                              catch(error)
                              {
                                  throw new Error('no Ajax support?');
                              }
                          }
                      }
                      if (typeof ret !== 'object')
                      {
                          throw new Error('No Ajax, FFS');
                      }
                      ret.open(method, url, true);
                      ret.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
                      ret.setRequestHeader('Content-type', (json ? 'application/json' : 'application/x-www-form-urlencode'));
                      ret.onreadystatechange = success;
                      ret.send((json ? JSON.stringify(str) : formalizeObject(str)));
                      return true;
                  }
                  
                  function jAjax(str,url)
                  {
                      $.ajax(
                      {
                          url : url,
                          data: str,
                          type: 'POST',
                          success: function(res)
                          {
                              console.log(res);
                          }
                      });
                  }
                  

                  我嘗試發出 Ajax 請求的四種方式:

                  Four ways in which I've tried to make the Ajax request:

                  jAjax({data:{foo:'bar'}},getUrl());//1
                  jAjax({data:{foo:'bar'}},getUrl(),true);//2
                  ajax({data:{foo:'bar'}},getUrl());//3
                  ajax({data:{foo:'bar'}},getUrl(),true);//4
                  

                  1. jAjax({data:{foo:'bar'}},getUrl());:這很好用:

                  []{"ajax":true,"controller":"index","action":"ajax","module":"default","identity":{},"data":{"foo:酒吧"}}參數:data[foo] 'bar' 來源:data%5Bfoo%5D=Bar(來自 FB 控制臺的 POST 選項卡)頭文件:application/x-www-form-urlencoded;字符集=UTF-8
                  所有這些都發送到以下網址:http://www.foo.bar/index/ajax?data%5Bfoo%5D=bar

                  []{"ajax":true,"controller":"index","action":"ajax","module":"default","identity":{},"data":{"foo":"Bar"}} Parameters: data[foo] 'bar' And Source: data%5Bfoo%5D=Bar (from POST tab in FB console) Header: application/x-www-form-urlencoded; charset=UTF-8
                  All of this was sent to the following url: http://www.foo.bar/index/ajax?data%5Bfoo%5D=bar

                • 但是這不起作用:

                • This doesn't work, however:

                  []{"ajax":true,"controller":"index","action":"ajax","module":"default","identity":{}} 是響應FB 中的 POST 選項卡:JSON 數據:{foo:'Bar'} 源:{"data":{"Foo":"Bar"}}(但相同的 url 是 case 1)標題:json;字符集=UTF-8

                  []{"ajax":true,"controller":"index","action":"ajax","module":"default","identity":{}} is the response POST tab in FB: JSON data: {foo:'Bar'} source: {"data":{"Foo":"Bar"}} (but same url is case 1) Header: json; charset=UTF-8

                • 這是最重要的:完整的請求 url 與案例 1 中的 url 相同,標題也是如此,但當我查看 POST 選項卡時在 FB 控制臺中(檢查請求)這是我能找到的唯一區別:

                • This is the big one: the full request url is identical to url from case 1, as are the headers BUT when I look at the POST tab in the FB console (inspect the request) This is the only difference I can find:

                  case 1: 參數:data[foo] 'bar' 來源:data%5Bfoo%5D=Bar
                  在這種情況下,我看不到參數部分,只有:來源:data%5Bfoo%5D=Bar

                  case 1: Parameters: data[foo] 'bar' Source: data%5Bfoo%5D=Bar
                  In this case, I can't see the Parameters section, only: Source: data%5Bfoo%5D=Bar

                • 與 case2 相同,除了 url,我想我忘記通過 encodeURI 傳遞.這個案子現在不太重要.我想/希望我能在弄清楚案例 3 有什么問題的那一刻開始工作.

                • Identical to case2, except for the url, which I think I forgot to pass through encodeURI. This case is less important for now. I think/hope I'll get this working the moment I figure out what's wrong with case 3.

                  在所有 4 種情況下,請求都被發送和接收.控制器動作如下:

                  In all 4 cases, the request is sent, and received. The controller action is as follows:

                  public function ajaxAction()
                  {
                      $this->_helper->layout->disableLayout();
                      $this->getHelper('viewRenderer')->setNoRender();
                      $this->_helper->getHelper('AjaxContext')->addActionContext( 'ajax' , 'json' )
                                                              ->initContext('json');
                      if($this->getRequest()->isPost() && $this->getRequest()->isXmlHttpRequest())
                      {
                          echo json_encode(array_merge(array('ajax'=>true),$this->_getAllParams()));
                      }
                      else
                      {
                          throw new Exception('no ajax call made??');
                      }
                  }
                  

                  因為我收到一個 JSON 字符串,所以我確定請求已發布,并且具有正確的 XMLHttpRequest 標頭.那么,為什么我不能發布 JSON 對象?更重要的是:為什么情況 3 不起作用?我不知道 jQuery 在做什么?是什么使案例 1 起作用,而案例 3 不起作用?

                  Since I'm receiving a JSON string, I'm sure the request is posted, and has the correct XMLHttpRequest header. Why then, can't I post JSON objects? Even more to the point: why is case 3 not working? What is jQuery doing that I'm not aware of? What is it, that makes case 1 to work, but not case 3?

                  PS:這可能無關緊要,但在瘋狂的時刻我嘗試添加:ret.setRequestHeader('Connection','close');ajax 函數,但我注意到,在發送的標頭中,Connection 設置為保持活動狀態.也許這可以讓某人知道出了什么問題?

                  PS: It might be irrelevant, but in a moment of madness I tried adding this: ret.setRequestHeader('Connection','close'); to the ajax function, but I noticed that, in the header that got sent out, Connection was set to keep-alive all the same. Perhaps this gives someone a clue as to what went wrong?

                  提前致謝

                  推薦答案

                  如果有人想知道出了什么問題:

                  In case anybody wonders what was wrong:

                  ret.setRequestHeader('Content-type', 'application/x-www-form-urlencode');
                  

                  應該是x-www-form-urlencoded",最后是d":

                  Should have been "x-www-form-urlencoded", with a "d" in the end:

                  ret.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                  

                  發送一個形式化對象現在可以工作了,我可以擺脫 jQuery :-)

                  sending a formalized object is now working, and I can get rid of jQuery :-)

                  這篇關于JavaScript Ajax 請求 vs jQuery $.ajax的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
                • 相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tbody id='BDhUN'></tbody>
                    <bdo id='BDhUN'></bdo><ul id='BDhUN'></ul>

                      • <i id='BDhUN'><tr id='BDhUN'><dt id='BDhUN'><q id='BDhUN'><span id='BDhUN'><b id='BDhUN'><form id='BDhUN'><ins id='BDhUN'></ins><ul id='BDhUN'></ul><sub id='BDhUN'></sub></form><legend id='BDhUN'></legend><bdo id='BDhUN'><pre id='BDhUN'><center id='BDhUN'></center></pre></bdo></b><th id='BDhUN'></th></span></q></dt></tr></i><div class="rbjxd55" id='BDhUN'><tfoot id='BDhUN'></tfoot><dl id='BDhUN'><fieldset id='BDhUN'></fieldset></dl></div>
                        <tfoot id='BDhUN'></tfoot>
                        1. <small id='BDhUN'></small><noframes id='BDhUN'>

                          <legend id='BDhUN'><style id='BDhUN'><dir id='BDhUN'><q id='BDhUN'></q></dir></style></legend>

                          1. 主站蜘蛛池模板: 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | VOC检测仪-甲醛检测仪-气体报警器-气体检测仪厂家-深恒安科技有限公司 | 通风天窗,通风气楼,屋顶通风天窗,屋顶通风天窗公司 | 电抗器-能曼电气-电抗器专业制造商| 上海办公室装修,写字楼装修—启鸣装饰设计工程有限公司 | 气密性检测仪_气密性检测设备_防水测试仪_密封测试仪-岳信仪器 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 煤机配件厂家_刮板机配件_链轮轴组_河南双志机械设备有限公司 | 青岛代理记账_青岛李沧代理记账公司_青岛崂山代理记账一个月多少钱_青岛德辉财税事务所官网 | 阻垢剂,反渗透阻垢剂,缓蚀阻垢剂-山东普尼奥水处理科技有限公司 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 污水/卧式/潜水/钻井/矿用/大型/小型/泥浆泵,价格,参数,型号,厂家 - 安平县鼎千泵业制造厂 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 智能交通网_智能交通系统_ITS_交通监控_卫星导航_智能交通行业 | 昆山新莱洁净应用材料股份有限公司-卫生级蝶阀,无菌取样阀,不锈钢隔膜阀,换向阀,离心泵 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 照相馆预约系统,微信公众号摄影门店系统,影楼管理软件-盟百网络 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 全自动固相萃取仪_高通量真空平行浓缩仪-勤业永为 | 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | cnc精密加工_数控机械加工_非标平键定制生产厂家_扬州沃佳机械有限公司 | 胜为光纤光缆_光纤跳线_单模尾纤_光纤收发器_ODF光纤配线架厂家直销_北京睿创胜为科技有限公司 - 北京睿创胜为科技有限公司 | 铝合金风口-玻璃钢轴流风机-玻璃钢屋顶风机-德州东润空调设备有限公司 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 管家婆-管家婆软件-管家婆辉煌-管家婆进销存-管家婆工贸ERP | NMRV减速机|铝合金减速机|蜗轮蜗杆减速机|NMRV减速机厂家-东莞市台机减速机有限公司 | 全自动真空上料机_粉末真空上料机_气动真空上料机-南京奥威环保科技设备有限公司 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 | 深圳装修_店面装修设计_餐厅设计_装修全包价格-尚泰装饰设计 | 进口试验机价格-进口生物材料试验机-西安卡夫曼测控技术有限公司 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 滚筒线,链板线,总装线,流水线-上海体能机电有限公司 | ptc_浴霸_大巴_干衣机_呼吸机_毛巾架_电动车加热器-上海帕克 | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 有福网(yofus.com)洗照片冲印,毕业聚会纪念册相册制作个性DIY平台 |