我的代码在codepen中,它的链接是: https://codepen.io/mlestina/pen/OZpOQW?editors=1111
我永远无法从Wiki API收到任何数据。
Contr-Shift-J读数是:
Loading failed for the <script> with source “https://en.wikipedia.org/w/api.php?action=opensearch&search=dsfds&callback=jQuery331010723807837372779_1525209741598&_=1525209741599”. index.html:1
An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can remove its sandboxing. OZpOQW
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://static.codepen.io/assets/telefon/bold/af889c53-1ee3-4868-8fdc-2b310d587b50-3-b7a87e0fbd213943fae0c0ef5985635dd43fa9c24876b2725127a13ccaf4ab6a.woff. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)
downloadable font: download failed (font-family: "Telefon" style:normal weight:normal stretch:normal src index:0): bad URI or cross-site access not allowed source: https://static.codepen.io/assets/telefon/bold/af889c53-1ee3-4868-8fdc-2b310d587b50-3-b7a87e0fbd213943fae0c0ef5985635dd43fa9c24876b2725127a13ccaf4ab6a.woff unknown:1:24452
Loading failed for the <script> with source “https://en.wikipedia.org/w/api.php?action=opensearch&search=Hitler&callback=jQuery33109582690097080016_1525209907566&_=1525209907567”. index.html:1
This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features! OZpOQW
HTML是:
<body>
<form>
<input type="text" name="a" id="a"><br>
<button onclick="passToJ()">Search</button>
</form>
</body>
和Javascript是:
function passToJ() {
var searchTerm = document.getElementById('a').value;
console.log("inside function, searchTerm is: ", searchTerm, " and x is: ", x);
var wikiLink = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchTerm + "&callback=?";
$.ajax({
url: wikiLink,
dataType: "jsonp",
type: "GET",
success: function(data) {
console.log(data);
},
error: function() {
console.log('error occurred');
}
})};
答案 0 :(得分:0)
我终于从另一个论坛得到了答案。
要么是;
1)包括event.preventDefault();在javascript代码中,或
2)从HTML中删除Form和/ Form标签
马特