脚本

JavaScript: How do I create JSONP?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a two domains, example1.com and example2.com From example1.com, I would like call a JSON API I have on example2.com. Knowing that this is not allowed, it occurred to me - this is exactly why JSON P was created. Question is, how do I modify my JSON API to make it JSONP capable? Basically, how do I create the callback api? UPDATE My server side language is PHP 回答1: It is simple. Simply accept a parameter called callback in the GET. Then wrap the callback JavaScript function around your data. Example in PHP: <?php $data = '{}'; // json

Single page application - load js file dynamically based on partial view

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've just started learning Angular and following the tutorial here - http://docs.angularjs.org/tutorial/step_00 I'm downloaded the seed example from GitHub and it works great. I have a question though - if a partial view requires an external js file to be referenced, does it need to be added to the index.html file at the beginning? I want the app to be as lean as possible and only want to include the js references that are required for the present view. Is it possible to load the js files dynamically based on a view? 回答1: I think this

What does set -e mean in a bash script?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file. The script has the following code: #!/bin/bash set -e # Automatically added by dh_installinit if [ "$1" = install ]; then if [ -d /usr/share/MyApplicationName ]; then echo "MyApplicationName is just installed" return 1 fi rm -Rf $HOME/.config/nautilus-actions/nautilus-actions.conf rm -Rf $HOME/.local/share/file-manager/actions/* fi # End automatically added section My first query is about the line: set

Displaying subprocess output to stdout and redirecting it

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 选择语言 中文(简体) 日语 英语 中文(繁体) 由 翻译 强力驱动 问题: I'm running a script via Python's subprocess module. Currently I use: p = subprocess . Popen ( '/path/to/script' , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) result = p . communicate () I then print the result to the stdout. This is all fine but as the script takes a long time to complete, I wanted real time output from the script to stdout as well. The reason I pipe the output is because I want to parse it. 回答1: To save subprocess' stdout to a variable for further processing and to display

chrome.tabs returns undefined in content script

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: chrome.tabs returns undefined despite the fact I set tabs in the permissions block. "permissions": [ "tabs", "http://*/*", "https://*/*" ], "content_scripts": [ { "matches": [ "http://*/*", "https://*/*" ], "js": [ "js/myScript.js" ], "all_frames": true } ], But in myScript.js the following returns undefined. chrome.tabs 回答1: As content script has its own limitations, chrome.tabs is only available in background scripts and popup scripts. If you wanna to use chrome.tabs then pass message from content_script to background script and play with

Mismatched anonymous define() module

匿名 (未验证) 提交于 2019-12-03 02:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting this error when I browse my webapp for the first time (usually in a browser with disabled cache). Error: Mismatched anonymous define() module: function (require) { HTML : <html> . . . <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script> var require = { urlArgs: "v=0.4.1.32" }; </script> <script data-main="assets/js/main" src="assets/js/libs/require.js"></script> <script src="assets/js/ace/ace.js?v=0.4.1.32"></script> </body> </html> JS : $(function () { define(function (require) { // do

MVC5, AjaxHelper, and the Correct Scripts &amp; Load Order

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: OK, I find it EXTREMELY ridiculous that I have to post a new question to find the answer but, alas here I am. Let's make this as simple as possible for the next wayward soul looking to resolve this. What are all the most current scripts I require to get the ajax form working? Thus far I have; <script src = "//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.js" ></script> <script src = "//ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.min.js" ></script> <script src = "//ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate

Webpack ProvidePlugin vs externals?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm exploring the idea of using Webpack with Backbone.js . I've followed the quick start guide and has a general idea of how Webpack works, but I'm unclear on how to load dependency library like jquery / backbone / underscore. Should they be loaded externally with <script> or is this something Webpack can handle like RequireJS's shim? According to the webpack doc: shimming modules , ProvidePlugin and externals seem to be related to this (so is bundle! loader somewhere) but I cannot figure out when to use which. Thanks 回答1: It's both possible

jQuery $.cookie is not a function

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to set a cookie using jQuery: $.cookie("testCookie", "hello"); alert($.cookie("testCookie")); But when I load my page, I receive the error "$.cookie is not a function". Here is what I know: I have downloaded the jQuery cookie plugin here . I am linking to jQuery and THEN the cookie plugin. Both jQuery and jQuery.cookie are loading correctly with 200 OKs. I have looked at several other answers ( here and here among others), to which most people suggested renaming the cookie.js file. I have renamed my cookie file "jquery.cookeee.js

The ScriptManager must appear before any controls that need it

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a new ASP.NET Web Application, and after debugging i got Server Error The control with ID 'WaitingPopup1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it. I'm new with ASP.NET so where schould i install my ScriptManager, in the web.config? 回答1: The ScriptManager is a control that needs to be added to the page you have created. Take a look at this Sample AJAX Application . <body> <form runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>