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

    • <bdo id='m0C7L'></bdo><ul id='m0C7L'></ul>

    <tfoot id='m0C7L'></tfoot>
      <legend id='m0C7L'><style id='m0C7L'><dir id='m0C7L'><q id='m0C7L'></q></dir></style></legend>

        <small id='m0C7L'></small><noframes id='m0C7L'>

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

        執行用包含腳本標簽的 XMLHttpRequest 編寫的 Javas

        Executing Javascript written with XMLHttpRequest that contains script tags?(執行用包含腳本標簽的 XMLHttpRequest 編寫的 Javascript?)
          <legend id='RQmtw'><style id='RQmtw'><dir id='RQmtw'><q id='RQmtw'></q></dir></style></legend>

          <small id='RQmtw'></small><noframes id='RQmtw'>

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

                  本文介紹了執行用包含腳本標簽的 XMLHttpRequest 編寫的 Javascript?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  通過一個 Javascript 請求,XMLHttpRequest 響應一些額外的 Javascript,這些 Javascript 需要添加到請求頁面的頁面中.

                  Through a Javascript request, XMLHttpRequest responds with some additional Javascript that needs to be added to the page the requesting page.

                  使用 eval(),如果響應類似于:

                  Using eval(), if the response is something like:

                  alert('This is the js response');
                  

                  ...那么這樣就可以了.

                  ... then this works just fine.

                  但是,返回的文本可能如下所示:

                  However, the text returned could look something like this:

                  <script language="javascript">var checkVar='checkVar: value 1';</script>
                  

                  但很可能:

                  <script src="http://www.somesite.com/setCheckVarValue.js"></script> 
                  

                  ...需要在頁面上加載額外的JS.

                  ... where additional JS needs to be loaded on the page.

                  我已確保 XMLHttpRequest同步,因為我想在此之后立即引用 checkVar.

                  I have ensured that the XMLHttpRequest is synchronous, as I want to reference checkVar right after this.

                  所以:

                  <script type="text/javascript" src="http://www.mysite.com/addJSToPage.js" />
                  // at this point, since this is a synchronous call, page processing waits
                  // until the response is received that needs to include the additional JS
                  // to load; this, for testing sets the value of checkVar
                  
                  <script type="text/javascript" >
                      alert(checkVar);
                  </script>
                  

                  警報消息應為checkVar: value 1".

                  The alert message should read "checkVar: value 1".

                  由于其他原因,這不僅僅是在addJSToPaged.js中設置var checkVar那么簡單,所以我不是在尋找那種推薦.

                  For other reasons, this is not just as simple as setting var checkVar in addJSToPaged.js, so I'm not looking for that kind of recommendation.

                  我只是使用 alert(checkVar) 作為測試,以確保在響應中通過 JS 設置了一個值.

                  I'm using alert(checkVar) simply as a test to ensure that a value has been set through JS in the response.

                  我想我可以去掉開始和結束腳本標記,并保持 eval() 的方式.但是,我想知道是否有任何解決方案支持我正在尋找的東西?

                  I suppose that I could strip out the beginning and ending script tags and keep the eval() way of doing it. However, I would like to know if there are any solutions that support what I'm looking for?

                  謝謝.

                  更新

                  按照 Prashanth 的建議,我在 addJSToPage.js 中添加了:

                  Following Prashanth's suggestion, in addJSToPage.js I added:

                  var dynamicElement = document.createElement('div');
                  

                  然后在 XMLHttpRequest 的響應中,我做了:

                  Then in the response from the XMLHttpRequest, I did:

                  dynamicElement.appendChild = xmlhttp.responseText;
                  

                  仍然沒有看到 checkVar 的值.

                  Still not seeing the value of checkVar.

                  推薦答案

                  重述 - 需要能夠在加載之后/期間將某些內容動態加載到頁面上,并讓它執行.通過執行,我不僅僅意味著更改某些 div 上的文本 - 這很容易.但是,如果我們想動態加載一些新的 JS,比如說來自某個外部源的警報,并注入它,連同它的腳本標簽,也許還有一些其他 HTML 代碼,那么解決方案是使用以下 jQuery 調用:

                  Recapping - the need is present to be able to dynamically load some content onto a page after/during load, and have it execute. By execute, I don't just mean change the text on some div - that's easy. But if we want to load some new JS dynamically, say an alert that comes from some outside source, and inject it, along with it's script tags, and maybe some other HTML code, then the solution is to use the following jQuery call:

                  jQuery(dynamicResponse).appendTo('body');
                  

                  dynamicResponse 來自異步 $.ajax({})XmlHttpRequest 響應.一旦出現,它就會被附加到任何 DOM 元素上,在 appendTo() 中指定并執行.

                  dynamicResponse comes from an asynchronous $.ajax({}) or XmlHttpRequest response. Once present, it is appended onto whatever DOM element, specified in appendTo() and executed.

                  這篇關于執行用包含腳本標簽的 XMLHttpRequest 編寫的 Javascript?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  <i id='03yG4'><tr id='03yG4'><dt id='03yG4'><q id='03yG4'><span id='03yG4'><b id='03yG4'><form id='03yG4'><ins id='03yG4'></ins><ul id='03yG4'></ul><sub id='03yG4'></sub></form><legend id='03yG4'></legend><bdo id='03yG4'><pre id='03yG4'><center id='03yG4'></center></pre></bdo></b><th id='03yG4'></th></span></q></dt></tr></i><div class="pvlddfn" id='03yG4'><tfoot id='03yG4'></tfoot><dl id='03yG4'><fieldset id='03yG4'></fieldset></dl></div>

                      <small id='03yG4'></small><noframes id='03yG4'>

                          <tbody id='03yG4'></tbody>

                            <bdo id='03yG4'></bdo><ul id='03yG4'></ul>
                          • <legend id='03yG4'><style id='03yG4'><dir id='03yG4'><q id='03yG4'></q></dir></style></legend>
                            <tfoot id='03yG4'></tfoot>

                          • 主站蜘蛛池模板: 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 挖掘机挖斗和铲斗生产厂家选择徐州崛起机械制造有限公司 | 通风气楼_通风天窗_屋顶风机-山东美创通风设备有限公司 | 小型气象站_便携式自动气象站_校园气象站-竞道气象设备网 | 银川美容培训-美睫美甲培训-彩妆纹绣培训-新娘化妆-学化妆-宁夏倍莱妮职业技能培训学校有限公司 临时厕所租赁_玻璃钢厕所租赁_蹲式|坐式厕所出租-北京慧海通 | 荣事达手推洗地机_洗地机厂家_驾驶式扫地机_工业清洁设备 | 山东彩钢板房,山东彩钢活动房,临沂彩钢房-临沂市贵通钢结构工程有限公司 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 北京企业宣传片拍摄_公司宣传片制作-广告短视频制作_北京宣传片拍摄公司 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 爆炸冲击传感器-无线遥测传感器-航天星百科| 济南品牌设计-济南品牌策划-即合品牌策划设计-山东即合官网 | 机房监控|动环监控|动力环境监控系统方案产品定制厂家 - 迈世OMARA | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 带压开孔_带压堵漏_带压封堵-菏泽金升管道工程有限公司 | 洁净实验室工程-成都手术室净化-无尘车间装修-四川华锐净化公司-洁净室专业厂家 | 万师讲师网-优质讲师培训师供应商,讲师认证,找讲师来万师 | 空心明胶胶囊|植物胶囊|清真胶囊|浙江绿键胶囊有限公司欢迎您! | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 软膜天花_软膜灯箱_首选乐创品牌_一站式天花软膜材料供应商! | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 顶呱呱交易平台-行业领先的公司资产交易服务平台 | 北京中航时代-耐电压击穿试验仪厂家-电压击穿试验机 | 高压管道冲洗清洗机_液压剪叉式升降机平台厂家-林君机电 | 电动葫芦-河北悍象起重机械有限公司| 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 余姚生活网_余姚论坛_余姚市综合门户网站 | 泰国试管婴儿_泰国第三代试管婴儿_泰国试管婴儿费用/多少钱_孕泰来 | 成都中天自动化控制技术有限公司 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 常州翔天实验仪器厂-恒温振荡器-台式恒温振荡器-微量血液离心机 恒温恒湿箱(药品/保健品/食品/半导体/细菌)-兰贝石(北京)科技有限公司 | 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | 节流截止放空阀-不锈钢阀门-气动|电动截止阀-鸿华阀门有限公司 | 青岛空压机,青岛空压机维修/保养,青岛空压机销售/出租公司,青岛空压机厂家电话 | 中控室大屏幕-上海亿基自动化控制系统工程有限公司 | 板框压滤机-隔膜压滤机-厢式压滤机生产厂家-禹州市君工机械设备有限公司 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 |