简体   繁体   English

未捕获到的SyntaxError:yii中出现意外的令牌<

[英]Uncaught SyntaxError: Unexpected token < in yii

I'm new to yii..i create one form in that i want to include the validations so i create one external file if i include that i got this error in chrome..if i select inspect elements it shows the html page but i use only php file how to recover it.how to include the external js in php on yii.i use one method tell me is that right or wrong. 我是yii的新手。.我要创建一个表单,因为我想包括验证,所以如果我在chrome中收到此错误,则创建一个外部文件。如果我选​​择检查元素,它将显示html页面,但是我仅使用php文件如何恢复它。如何在yii.i上的php中包含外部js。使用一种方法告诉我是对还是错。

 <?php $baseUrl = Yii::app()->baseUrl; $cs = Yii::app()->getClientScript(); $cs->registerScriptFile($baseUrl.'/js/logincheck.js'); ?> <?php /* @var $this SiteController */ /* @var $model LoginForm */ /* @var $form CActiveForm */ $this->pageTitle=Yii::app()->name . ' - SimpleLogin'; $this->breadcrumbs=array( 'SimpleLogin', ); ?> <h1>Login</h1> <p>Please fill out the following form with your login credentials:</p> <div class="form" onsubmit="check()"> <?php $url=Yii::app()->createAbsoluteUrl('site/newlogin'); echo CHtml::beginForm($url,'POST') ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <div class="row",id="s"> <?php echo CHtml::label('name',''); ?> <?php echo CHtml::textField('name','',array('onblur'=>"keyw()",'id'=>'s')); ?> </div> <div class="row"> <?php echo CHtml::label('password',''); ?> <?php echo CHtml::passwordField('password',''); ?> </div> <div class="row"> <?php echo CHtml::dropDownList('role','', array('M' => 'Male', 'F' => 'Female'), array('empty' => '(Select a gender)')); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton('Submit',array('name'=>'submit')); ?> </div> <?php echo CHtml::encode($model->name)."-". CHtml::encode($model->password)."-".CHtml::encode($model->role);?> <?php echo CHtml::endForm(); ?> </div><!-- form --> 

As you said in the comments, you see check() is not defined error. 正如您在评论中所说,您看到check() is not defined错误。 This means The external javascript file(logincheck.js) isn't included properly . 这意味着未正确包含外部javascript文件(logincheck.js) So, browser cant find check() function. 因此,浏览器无法找到check()函数。 Therefore, one possible problem is Path to js file . 因此,一个可能的问题是js文件的路径 As a result $cs->registerScriptFile($baseUrl.'/js/logincheck.js') is the first possible problem. 结果$cs->registerScriptFile($baseUrl.'/js/logincheck.js')是第一个可能的问题。 Another possibility: there are somethings wrong inside logincheck.js file, for example syntax errors. 另一种可能性: logincheck.js文件内部存在某些错误,例如语法错误。 You can inspect the browser console errors for more information. 您可以检查浏览器控制台错误以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM