First on the code:
This is the view site/reg.php.
$cs = Yii::app ()->getclientscript (); $cs->registerscriptfile ('/js/verify-code.js ', Cclientscript::P os_end);
This is layout/main.php.
$commonValue = Json_encode ([ ' smsverifycodeurl ' = + Yii::app ()->createabsoluteurl (' Site/sendsmscode '), ' Waitsecond ' = wapmember::D efault_interval, ]); Yii::app ()->clientscript->registerscript ("var commonvalue = $commonValue", Cclientscript::P os_end);
This is the Verify-code.js file.
var initsecond = (typeof commonvalue.waitsecond) = = "undefined"? 180:commonvalue.waitsecond, waitsecond =initsecond, smsverifycode = function (btn, form) {this.getbtn = btn; th Is.form = form;}, SCF;
This is Chrom's browser error.
verify-code.js:1 Uncaught ReferenceError: CommonValue is not defined
Reply content:
Finally found:
It was written in the original
Yii::app ()->clientscript->registerscript ("var commonvalue = $commonValue", Cclientscript::P os_end);
One parameter is missing. The result is such a drop:
Yii::app ()->clientscript->registerscript (' Commonvalue ', "var commonvalue = $commonValue", Cclientscript::P os_ END);
The pos_end of Commonvalue is simply adjusted to Pos_head.
Or make sure the $commonValue is placed in main.php before render (' reg.php '), two times Registerscript is in sequence
Ps:
Verify-code.js can I return a function or an object instead of referencing a global variable in this file?
Had previously maintained such a code, disgusting a ratio of
The above is yii in the view to create a variable (the code to protect PHP), in the JS file to invoke the previously created variables of the code instance of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!