gpt4 book ai didi

javascript - Yii Ajax 在 LimeSurvey 插件环境中返回整个网页。为什么?

转载 作者:行者123 更新时间:2023-11-27 23:58:57 25 4
gpt4 key购买 nike

在 LimeSurvey 的插件环境中,我在 View 文件中截取了以下代码,它将打印出两个相关下拉列表:

<?php echo CHtml::dropDownList('survey_id', '', CHtml::listData(Survey::model()->active()->findAll(), 'sid', function($survey){return $survey->getLocalizedTitle()." ($survey->sid)";}), array(
'ajax' => array(
'type' => 'POST', //request type
'cache' => false,
'url' => 'direct?plugin=AcornReporting&function=MaturityLevels&action=dynamicResponses', //url to call.
'update' => '#AcornMaturityLevels_response_id', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)));

//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('response_id','', array(), array('style'=>'margin-left: 20px')); ?>

在相应的 Controller 中,以下代码应处理ajax请求:

public function actionDynamicResponses() {
$data = CHtml::listData(Response::model($_POST['survey_id'])->findAll(), 'id', 'id');

foreach ($data as $value => $name) {
echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
}
}

chrome 开发工具中看到的响应让我感到惊讶。 第一行是我所期望的。但接下来是一个完整的网页,我不知道它来自哪里。

<option value="1">1</option><!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="shortcut icon" href="/acorn/acorn-htmstyles/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/acorn/acorn-htmstyles/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/third_party/qTip2/dist/jquery.qtip.min.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/third_party/jquery-superfish/css/superfish.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/third_party/jquery-notify/ui.notify.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/5dcd5e76/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/5dcd5e76/css/bootstrap-yii.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/7666aa2b/acorn.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles/gringegreen/jquery-ui/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles/gringegreen/printablestyle.css" media="print" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles/adminstyle.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles/gringegreen/adminstyle.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles-public/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles-public/jquery.multiselect.filter.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/styles/gringegreen/displayParticipants.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/7165e62e/css/notify.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/b27bf437/nav.css" />
<link rel="stylesheet" type="text/css" href="/acorn/acorn-htm/tmp/assets/5dcd5e76/css/select2.css" />
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/5dcd5e76/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jqueryui/js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/qTip2/dist/jquery.qtip.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jquery-superfish/js/superfish.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jquery-superfish/js/hoverIntent.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jquery-cookie/jquery.cookie.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/third_party/jquery-notify/src/jquery.notify.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/5dcd5e76/js/bootstrap.bootbox.min.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/scripts/admin/admin_core.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/13abf2bc/script.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/b27bf437/nav.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
LS.data = {"baseUrl":"http:\/\/localhost\/acorn\/acorn-htm","showScriptName":true,"urlFormat":"path","adminImageUrl":"\/acorn\/acorn-htm\/styles\/gringegreen\/images\/","csrfToken":"e5329206519e6671e4962fac47a933a29149dfb0","replacementFields":{"path":"\/acorn\/acorn-htm\/index.php\/admin\/limereplacementfields\/sa\/index"}};
$.ajaxSetup({data: {YII_CSRF_TOKEN: LS.data.csrfToken}});
LSdebug = {"session":{"adminlang":"en","LSWebUser":{"__returnUrl":"\/acorn\/acorn-htm\/index.php\/plugins\/","__id":"1","__name":"admin","__states":{},"plugin":"Authdb"},"loginID":1,"user":"admin","full_name":"Administrator","htmleditormode":"default","templateeditormode":"default","questionselectormode":"default","dateformat":"1","session_hash":"697c7382a18ddfd48d3ac4bd1d6f5dc70df1ba2c4a86a2dffb8145896438ee95","USER_RIGHT_INITIALSUPERADMIN":1,"just_logged_in":true,"loginsummary":"<br \/>Welcome Administrator!<br \/>&nbsp;"},"server":{"HTTP_HOST":"localhost","HTTP_CONNECTION":"keep-alive","CONTENT_LENGTH":"231","HTTP_ACCEPT":"*\/*","HTTP_ORIGIN":"http:\/\/localhost","HTTP_X_REQUESTED_WITH":"XMLHttpRequest","HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/44.0.2403.155 Safari\/537.36","CONTENT_TYPE":"application\/x-www-form-urlencoded; charset=UTF-8","HTTP_REFERER":"http:\/\/localhost\/acorn\/acorn-htm\/index.php\/plugins\/direct?plugin=AcornReporting&function=MaturityLevels&action=create","HTTP_ACCEPT_ENCODING":"gzip, deflate","HTTP_ACCEPT_LANGUAGE":"de-CH,de;q=0.8,en;q=0.6,de-DE;q=0.4,en-US;q=0.2","HTTP_COOKIE":"YII_CSRF_TOKEN=e5329206519e6671e4962fac47a933a29149dfb0; PHPSESSID=8sc7m2t2df348epd8his1c9vn7","HTTP_DNT":"1","PATH":"\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin","SERVER_SIGNATURE":"<address>Apache\/2.4.7 (Ubuntu) Server at localhost Port 80<\/address>\n","SERVER_SOFTWARE":"Apache\/2.4.7 (Ubuntu)","SERVER_NAME":"localhost","SERVER_ADDR":"127.0.0.1","SERVER_PORT":"80","REMOTE_ADDR":"127.0.0.1","DOCUMENT_ROOT":"\/var\/www\/html","REQUEST_SCHEME":"http","CONTEXT_PREFIX":"","CONTEXT_DOCUMENT_ROOT":"\/var\/www\/html","SERVER_ADMIN":"webmaster@localhost","SCRIPT_FILENAME":"\/var\/www\/html\/acorn\/acorn-htm\/index.php","REMOTE_PORT":"33729","GATEWAY_INTERFACE":"CGI\/1.1","SERVER_PROTOCOL":"HTTP\/1.1","REQUEST_METHOD":"POST","QUERY_STRING":"plugin=AcornReporting&function=MaturityLevels&action=dynamicResponses","REQUEST_URI":"\/acorn\/acorn-htm\/index.php\/plugins\/direct?plugin=AcornReporting&function=MaturityLevels&action=dynamicResponses","SCRIPT_NAME":"\/acorn\/acorn-htm\/index.php","PATH_INFO":"\/plugins\/direct","PATH_TRANSLATED":"\/var\/www\/html\/plugins\/direct","PHP_SELF":"\/acorn\/acorn-htm\/index.php\/plugins\/direct","REQUEST_TIME_FLOAT":1439512250.393,"REQUEST_TIME":1439512250}};
console.dir(LSdebug)

LS.messages=[];
/*]]>*/
</script>
<title>Limesurvey Administration</title>
</head>
<body>
<div class="wrapper clearfix">
<div id="notify-container" style="display:none;">
<div id="default-notify" class="ui-state-highlight ui-corner-all">
<p>
<a class="ui-notify-close" href="#"><span class="ui-icon ui-icon-close" style="float:right">&nbsp;</span></a>
<span style="float:left; margin:2px 5px 0 0;" class="ui-icon ui-icon-info">&nbsp;</span>
#{message}
</p>
</div>
<div id="error-notify" class="ui-state-highlight ui-corner-all ui-state-error error">
<p>
<a class="ui-notify-close" href="#"><span class="ui-icon ui-icon-close" style="float:right">&nbsp;</span></a>
<span style="float:left; margin:2px 5px 0 0;" class="ui-icon ui-icon-alert">&nbsp;</span>
#{message}
</p>
</div>
<!-- ui-state-success doesn't exist -->
<div id="success-notify" class="ui-state-highlight ui-corner-all ui-state-success success">
<p>
<a class="ui-notify-close" href="#"><span class="ui-icon ui-icon-close" style="float:right">&nbsp;</span></a>
<span style="float:left; margin:2px 5px 0 0;" class="ui-icon ui-icon-alert">&nbsp;</span>
#{message}
</p>
</div>
</div>
<div class="maintitle titlebar">Acorn Human and Talent Management</div> <div class="menubar">
<div class="menubar-title ui-widget-header"><div class="menubar-title-left"><strong>Administration</strong> -- Logged in as:<strong><a href="/acorn/acorn-htm/index.php/admin/user?sa=personalsettings"> admin <img src="/acorn/acorn-htm/styles/gringegreen/images/profile_edit.png" alt="Edit your personal preferences" /></a></strong></div></div><nav class="menubar"><ol class="menubar-left level0"><li><a href="/acorn/acorn-htm/index.php/admin/survey"><img src="/acorn/acorn-htm/styles/gringegreen/images/home.png" alt="Default administration page" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/user"><img src="/acorn/acorn-htm/styles/gringegreen/images/security.png" alt="Manage survey administrators" /></a></li><li><a href="/acorn/acorn-htm/index.php/admin/usergroups?sa=index"><img src="/acorn/acorn-htm/styles/gringegreen/images/usergroup.png" alt="Create/edit user groups" /></a></li><li><a href="/acorn/acorn-htm/index.php/admin/globalsettings"><img src="/acorn/acorn-htm/styles/gringegreen/images/global.png" alt="Global settings" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/checkintegrity"><img src="/acorn/acorn-htm/styles/gringegreen/images/checkdb.png" alt="Check data integrity" /></a></li><li><a href="/acorn/acorn-htm/index.php/admin/dumpdb"><img src="/acorn/acorn-htm/styles/gringegreen/images/backup.png" alt="Backup entire database" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/labels?sa=view"><img src="/acorn/acorn-htm/styles/gringegreen/images/labels.png" alt="Edit label sets" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/templates"><img src="/acorn/acorn-htm/styles/gringegreen/images/templates.png" alt="Template editor" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/participants"><img src="/acorn/acorn-htm/styles/gringegreen/images/cpdb.png" alt="Central participant database/panel" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins"><img src="/acorn/acorn-htm/styles/gringegreen/images/plugin.png" alt="Plugin manager" /></a></li><li><a href="http://localhost/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Cockpit"><img src="/acorn/acorn-htm/styles/gringegreen/images/bounce.png" alt="Acorn Reporting" /></a></li></ol><ol class="menubar-right level0"><li><label for="surveyid">Surveys:</label><select class="select" id="surveyid" data-route="admin/survey/sa/view" name="surveyid">
<option value=""></option>
<optgroup label="Expired">
<option value="142833">(Demo) 3 Groups, some questions</option>
<option value="91">Acorn TM Survey with 2 Ems</option>
<option value="957916">ATM Survey active</option>
<option value="296591">ATM Survey finished</option>
<option value="92">ATM Survey, EM test</option>
<option value="134138">Deutsche Börse AG, V0.1</option>
<option value="678544">Short survey for testing EM class</option>
<option value="116811">V0.1 Test</option>
</optgroup>
<optgroup label="Inactive">
<option value="957791">Acorn HTM V0.1</option>
<option value="944555">Acorn Talent Management Survey</option>
<option value="356369">All groups, some questions</option>
<option value="543114">Copy1 of ATMS</option>
<option value="14272">Test of EM question attributes</option>
<option value="532311">v1.0 All Questions</option>
<option value="912161">V2.0 All Questions für Testing</option>
</optgroup>
</select></li><li><a href="/acorn/acorn-htm/index.php/admin/survey?sa=index"><img src="/acorn/acorn-htm/styles/gringegreen/images/surveylist.png" alt="Detailed list of surveys" /></a></li><li><a href="/acorn/acorn-htm/index.php/admin/survey?sa=newsurvey"><img src="/acorn/acorn-htm/styles/gringegreen/images/add.png" alt="Create, import, or copy a survey" /></a></li><li><img src="/acorn/acorn-htm/styles/gringegreen/images/separator.gif" alt="" /></li><li><a href="/acorn/acorn-htm/index.php/admin/authentication?sa=logout"><img src="/acorn/acorn-htm/styles/gringegreen/images/logout.png" alt="Logout" /></a></li><li><a href="http://docs.limesurvey.org"><img src="/acorn/acorn-htm/styles/gringegreen/images/showhelp.png" alt="LimeSurvey online manual" /></a></li></ol></nav></div>
<div id="content">
<div class="acorn-page" >
<nav class="menubar acorn-menu clearfix">

<h1 class="acorn-plugin-title">Acorn Plugin</h1>

<ol class="menubar-left level0"><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Cockpit"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons_040_stats.png" alt="Cockpit" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Texts"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons-547-quote.png" alt="Texts" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Rules"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons-69-ruler.png" alt="Rules" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Rulesets"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons-140-adjust-alt.png" alt="Rulesets" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Reports"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons-609-newspaper.png" alt="Reports" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=ReportTemplates"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons-37-file.png" alt="Report Templates" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=MaturityLevels"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons_323_calculator.png" alt="Maturity Levels" /></a></li><li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=Customers"><img src="/acorn/acorn-htm/plugins/AcornReporting/assets/images/glyphicons/glyphicons_043_group.png" alt="Customers" /></a></li></ol>

</nav>
<ul class="nav pull-right acorn-dropdown-menu" style="width:160px" id="yw0">
<li class="dropdown user"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-user"></i><span class="username">Development</span> <i class="icon-angle-down"></i></a>
<ul class="dropdown-menu">
<li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=UnitTest"><i class="icon-road"></i>Unit Test controller</a></li>
<li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=TestEM"><i class="icon-warning-sign"></i>EM in action</a></li>
<li><a href="/acorn/acorn-htm/index.php/plugins/direct?plugin=AcornReporting&amp;function=TestEM&amp;action=UnitTestEM"><i class="icon-thumbs-up"></i>Unit Test EM</a></li>
<li><span></span></li>
<li><a href="#"><i class="icon-tasks"></i>Task</a></li>
</ul>
</li>
</ul>


<div class="container acorn-content">
</div>
</div>

</div>
<div id="ajaxprogress" title="Ajax request in progress" style="text-align: center">
<img src="/acorn/acorn-htm/styles/gringegreen//images/ajax-loader.gif"/>
</div>
</div>
<div class='footer'>
<div style='float:left;width:110px;text-align:left;'>
<a href='http://manual.limesurvey.org'><img alt='LimeSurvey - Online manual' title='LimeSurvey - Online manual' src='/acorn/acorn-htm/styles/gringegreen/images/docs.png' /></a>
</div>
<div style='float:right;'>
<a href='http://donate.limesurvey.org'><img alt='Support this project: Donate to LimeSurvey' title='Support this project: Donate to LimeSurvey!' src='/acorn/acorn-htm/styles/gringegreen/images/donate.png'/></a>
</div>
<div class='subtitle'><a class='subtitle' title='Visit our website!' href='http://www.limesurvey.org' target='_blank'>LimeSurvey</a><br />Version 2.05+ Build 150211</div>
</div> <script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/7165e62e/js/notify.js"></script>
<script type="text/javascript" src="/acorn/acorn-htm/tmp/assets/5dcd5e76/js/select2.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
jQuery('a[rel="tooltip"]').tooltip();
jQuery('a[rel="popover"]').popover();
jQuery('#surveyid').select2({'minimumResultsForSearch':10,'placeholder':'Please choose...'});
});
/*]]>*/
</script>
</body>

</html>

因此,下拉列表无法更新。

出了什么问题以及如何解决这个问题?

最佳答案

问题出在操作代码中。这可以通过使用 exit() 或更优雅地结束执行来解决 Yii:app()->end()

public function actionDynamicResponses() {
$data = CHtml::listData(Response::model($_POST['survey_id'])->findAll(), 'id', 'id');

foreach ($data as $value => $name) {
echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
}

// Gracefully end the action;
Yii:app()->end();
}

因为您依赖于 Controller 的正常退出,所以它的默认操作是渲染默认页面。通过使用 exit() 或 Yii::app()->end(),您可以告诉操作处理程序不要渲染布局。

您还可以通过覆盖 Controller 中的布局来实现此目的;

$this->layout=false;

关于javascript - Yii Ajax 在 LimeSurvey 插件环境中返回整个网页。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32000739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com