Loading Sequence problems encountered by jquery. artDialog in requireJS

Source: Internet
Author: User

Query. artDialog is estimated to not support AMD specifications. Therefore, when using the modular methods of requireJS and AMD, there is no problem during the start. Later, in the slow network environment, it was found that jquery was not fully loaded. artDialog has been loaded and an error is reported, causing you to refresh the page. The solution provided by requireJS is called shim, which has been tested for many times and figured out how to do it: logging, which contains the loginModule. js file: [html] <script data-main = ".. /script/app/loginModule "src = ".. /script/thirdParty/require. js "> </script> loginModule. js contains a configuration and a module definition: [javascript]/* global window, document */require. config ({paths: {"jquery ":".. /thirdParty/jquery-1.8.0.min "," ajaxuti.pdf Y ":". /ajaxUtility "," jquery. artDialog ":".. /.. /plugin/artDialog4.1.6/jquery. artDialog "," jqueryTool ":". /jqueryTool "," login ":". /login "}, shim: {" jquery. artDialog ": {deps: [" jquery "], exports:" artDialog "}}); define (" loginModule ", [" jquery "," ajaxUtility ", "dialog", "jqueryTool", "login"], function ($, ajaxUtility, dialog, jqueryTool, login) {'use strict '; var locale = window. locale; aja XUtility. init (locale); $ (document ). ready (function () {login. init (ajaxUtility, dialog, jqueryTool, locale) ;}); note that my loginModule is a module and relies on the dialog module. The dialog module is another module defined by myself. It depends on the jquery. artDialog module. The jquery. artDialog module demonstrates the dependency on jquery in shim. Now let's take a look at the module dialog. js that depends on jquery. artDialog. The following array shows the dependency, and the parameter uses the variable name exported from exports in shim. [Javascript] define ("dialog", ["jquery", "jquery. artDialog "], function ($, artDialog) {'use strict '; return {cancelText:" ", locale:" ", okText:" ", titleText :"", // language shoshould be either 'cn' or 'en' init: function (locale) {this. locale = locale; if (locale = "cn") {this. cancelText = "cancel"; this. okText = "OK"; this. errorTitleText = "error"; this. okTitleText = "info";} else {this. cancelText = "Cancel"; this. okText = "OK"; this. errorTitleText = "Error"; this. okTitleText = "Info" ;}}, error: function (message) {$. dialog ({title: this. errorTitleText, icon: "error", content: message, okVal: this. cancelText, OK: function () {this. close () ;}) ;}, done: function (message) {$. dialog ({title: this. okTitleText, icon: "OK", www.2cto.com content: message, okVal: this. okText, OK: function () {This. close () ;}};};}); To use RequireJS well, you need to be patient. to configure this stuff, simply read the document and repeat the experiment based on your actual situation. By the way, you only need to add require. config... To the js file directly referenced on the top level, that is, the html page. Other js files are not needed. If there are multiple pages, it is clear that you need multiple such top level files. Someone is called bootstrap and the name is also suitable.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.