【问题标题】:Embedded surveyJS Issue嵌入式调查JS问题
【发布时间】:2018-06-25 08:36:32
【问题描述】:

我正在按照指导 (https://surveyjs.io/Survey/Builder/) 在我的页面中嵌入调查。

在上述网站上> 嵌入调查>

  • 使用 jQuery
  • 用于引导框架
  • 在页面上显示调查。

我有一个 Laravel 应用,页面呈现这个源代码:

<!DOCTYPE html>
    <html lang="en">
    <head>
        <title>The Survey Page </title>

        <!-- Your platform (jquery) scripts. -->
        <link href="https://surveyjs.azureedge.net/1.0.28/survey.css" type="text/css" rel="stylesheet" />
        <script src="https://surveyjs.azureedge.net/1.0.28/survey.jquery.min.js"></script>

    </head>

    <body>
        <div id="surveyContainer"></div>
        <script> alert("This is the survey blade right here right now"); </script>
        <script>
            var surveyJSON = {pages:[{name:"page1",elements:[{type:"paneldynamic",name:"question2",templateElements:[{type:"radiogroup",name:"question3",choices:["item1","item2","item3"]},{type:"text",name:"question4"}]},{type:"paneldynamic",name:"question1"}]}]}

            function sendDataToServer(survey) {
                //send Ajax request to your web server later. Meantime...
                alert("The results are:" + JSON.stringify(survey.data));
            }

            var survey = new Survey.Model(surveyJSON);
            $("#surveyContainer").Survey({
                model: survey,
                onComplete: sendDataToServer
            });
        </script>


    </body>
</html>
  • 所以,我收到警报和空白页。
  • 外部脚本引用格式正确
  • 脚本是页面上的最后一件事(按顺序)

在控制台中,我得到了这个:

survey.jquery.min.js:11 Uncaught TypeError: Cannot read property 'fn' of undefined
    at Object.<anonymous> (survey.jquery.min.js:11)
    at t (survey.jquery.min.js:6)
    at survey.jquery.min.js:6
    at survey.jquery.min.js:6
    at survey.jquery.min.js:6
    at survey.jquery.min.js:6
(anonymous) @ survey.jquery.min.js:11
t @ survey.jquery.min.js:6
(anonymous) @ survey.jquery.min.js:6
(anonymous) @ survey.jquery.min.js:6
(anonymous) @ survey.jquery.min.js:6
(anonymous) @ survey.jquery.min.js:6

showSurvey:23 Uncaught ReferenceError: Survey is not defined
    at showSurvey:23

showSurvey 是我的控制器方法。

public function showSurvey()
    {
        return view ('surveys.survey');   //the laravel blade.. although it's just HTML as per the tutorial example
    }

我做错了什么?

【问题讨论】:

  • 您是否首先检查了浏览器控制台是否有错误?
  • @CBroe ...我看到一些错误...将它们添加到我的问题中
  • 很可能您只需要先嵌入 jQuery ...?
  • 掌心在哪里?我以为&lt;script src="https://surveyjs.azureedge.net/1.0.28/survey.jquery.min.js"&gt;&lt;/script&gt; 是 jquery。谢谢.. 非常感谢。让它成为我可以接受的答案?
  • 是的,这只是表示这是应该与 jQuery 一起使用的脚本版本……根据 github 自述文件,“它有版本用于 angular2+、jQuery、knockout、react 和 vue” - 所以这些很可能都会被相应地命名。

标签: javascript surveyjs


【解决方案1】:

请替换以下行:

  <!-- Your platform (jquery) scripts. -->

  <script src="https://unpkg.com/jquery"></script>

【讨论】:

  • 为什么要特别提到那个?我添加了&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;,效果很好。
  • 2.1.3 版本也很好。我们没有设置确切的版本,因为开发者可能使用不同的版本,我们没有任何具体要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 2015-01-13
  • 2014-04-04
相关资源
最近更新 更多