我无法摆脱这个错误,而且它刚刚开始在头部添加源代码希望能有效。什么可能导致这些错误?这是rails中的表单助手。
未捕获的ReferenceError:未定义jQuery 在select2.self-3d0dca634dc5f4aee8c2dddef05674d9a674214500fd7e89959dc9e7251bb717.js:18 在select2.self-3d0dca634dc5f4aee8c2dddef05674d9a674214500fd7e89959dc9e7251bb717.js:20 reports.self-125a9126dcda5f55eea80b80380e4bf42b79fb01ceba6fbb8c52674b3952fca7.js:2未捕获TypeError:$(...)。select2不是函数 at reports.self-125a9126dcda5f55eea80b80380e4bf42b79fb01ceba6fbb8c52674b3952fca7.js:2 at reports.self-125a9126dcda5f55eea80b80380e4bf42b79fb01ceba6fbb8c52674b3952fca7.js:4 报告:59 Uncaught SyntaxError:missing)在参数列表之后 application.self-a24973bbb6a25a64ef1e551cdacacf83cdc7ddd8e2ea49e5c4df1e07a115c569.js?body = 1:24未捕获TypeError:$(...)。select2不是函数 在HTMLDocument。 (application.self-a24973bbb6a25a64ef1e551cdacacf83cdc7ddd8e2ea49e5c4df1e07a115c569.js体= 1:24) 在火上(jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body = 1:3233) at Object.fireWith [as resolveWith](jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body = 1:3363) 在Function.ready(jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body = 1:3583) 在HTMLDocument.completed(jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body = 1:3618)
<header>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
</header>
<h1>Partner Scorecard Generator</h1>
<%= form_for(:report) do |f| -%>
<p>
<%=f.label "Run date" %><br>
<%=f.date_field :run_date %><br>
</p>
<p>
<script type = "text/javascript">
$(document).ready(function() {
console.log("setting up select 2");
$("#selecttwo").select2({
placeholder: "Select your Partners",
ajax: {
url: 'http://services.dwmholdings.com/order.svcs/api/partners',
dataType: 'json',
type: 'post',
processResults: function p(data){
console.log(processresults())
var mapped = $.map(data, funtion (obj){
obj.text = obj.text || obj.name;
obj.id = obj.id || obj.salesId;
console.log(mapped);
return obj;
})
return {
results: mapped
}
}
}
});
});
console.log("hello")
</script>
<%= select_tag :sales_ids %>
</p>
<p>
<%= f.label "Yes send Email" %>
<%= f.radio_button :send_email, "True" %><br>
<%= f.label "Do not Email" %>
<%= f.radio_button :send_email, "False" %>
</p>
<p>
<%= f.label "recipients" %>
<%= f.email_field(:recipients) %>
</p>
<p>
<%= f.label "bcc" %>
<%= f.email_field(:bcc)%>
</p>
<p>
<%= f.radio_button :Send_Email, "True" %>
<%= f.label :Debug, "Debug on" %><br>
<%= f.radio_button :Send_Email, "False" %>
<%= f.label :Debug, "Debug off" %>
</p>
<p>
<%=f.submit %>
</p>
<!-- :class => "selecttwo",
:multiple=>true,
:size =>20,
:id => "selecttwo" -->
<% end %>
答案 0 :(得分:0)
$("#foo").select2()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<div id="foo"></div>
在脚本https
中尝试使用http
代替src
。似乎在这个简化的例子中工作。
答案 1 :(得分:0)
您正在加载jquery.min.js以及jquery.js。尝试删除其中一个。如果姐妹或相同的javascripts被加载到同一页面上,则会发生此错误。