0

I tested validate plugin in html file by following its documentation, it works fine, but my project is base on require, so I removed script reference in the html then did this in require config.

var require = require || {
  paths : {
    jquery : "../libs/jquery/3.2.1/jquery-3.2.1.min",
    validate : "../libs/vd/validate/jquery.validate.min",
  },
  shim : {
    jquery : {
      exports : "$"
    },
    validate : {
      deps : [ "jquery" ],
      exports : "validate"
    }
  }
};

and also in js file:

define([ "jquery", "validate"], function($, validate) {...}

it works fine. Then I tried to add localize module by adding this into config file paths:

validateLocal : "../libs/vd/validate/localization/messages_zh.min"

also shim:

validateLocal : {
  deps : [ "jquery" ],
  exports : "validateLocal"
}

then in js file:

define([ "jquery", "validate", "validateLocal"], function($, validate, validateLocal) {...}

not working, also tried in shim:

validateLocal : {
  deps : [ "jquery", "validate" ],
  exports : "validateLocal"
}

not working either.

in all this 'not working' situations I got error in console:

require.js:5 GET http://localhost:9000/jquery.validate.min.js net::ERR_ABORTED

which attracted my attention because there the validate js file address is not the location I specified. so I tried to check the network loading, I found after I add the 'validateLocal part' in require config, browser (chrome latest) will load double times of validate.min.js, but from different locations. The first one is the right one from where I specified, the second one is this error one, which of course got 403 error.

I don't know why require loads double times of this file, who triggered it and who declared this address, why http://localhost:9000/jquery.validate.min.js ?

Tried googled it and searched on stackoverflow for a whole 6 hours, please help.

GLPease
  • 545
  • 1
  • 8
  • 19
  • Please read the detailed descriptions when using tags: the [tag:require] tag is not the same as the [tag:requirejs] tag. Edited. Once you know the correct tags, [searching SO does not take hours](https://stackoverflow.com/questions/tagged/jquery-validate+requirejs?sort=votes&pageSize=50). – Sparky Nov 28 '17 at 04:56
  • @Sparky Thanks for the editing and links, I read them, but there 2 links seem can not solve my question. I did exactly what they said, shim key match names, I could hardly see anywhere wrong of my code, though it should be. – GLPease Nov 28 '17 at 06:21
  • I finally found where the problem is, it is the define params in the "../libs/vd/validate/localization/messages_zh.min" file is wrong, there the wrong param requests for http://localhost:9000/jquery.validate.min.js. Thanks for the searching example, now I get how to search with tags :) – GLPease Nov 28 '17 at 06:41

0 Answers0