我正在尝试调用index.php中的函数,但出现此错误Uncaught ReferenceError: getWidget is not defined
。当我在widget.php中调用该函数时,它可以工作。如何获得函数getWidget(); 在index.php中工作?
我也在index.php中收到此警告
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost/widget.php".
和widget.php中的这个错误
Uncaught SyntaxError: Unexpected token <
这里是 index.php 和 widget.php
索引.php
<script type='text/javascript' src='widget.php'></script>
<a href="#" onclick="getWidget();">Launch Widget</a>
小部件.php
<!DOCTYPE HTML>
<head>
<script type="text/javascript" src="/scripts/jquery-1.7.1.min.js"></script>
<link href="/css/bootstrap/css/bootstrap.css" rel="stylesheet">
<script type='text/javascript' src='/css/bootstrap/js/bootstrap.min.js'></script>
<script type='text/javascript' src='/css/bootstrap/js/bootstrap-transition.js'></script>
</head>
<script type="text/javascript">
var http = getHTTPObject();
function doauth() {
setTimeout("doauth();", 15000);
iframe = document.createElement('iframe');
iframe.id = "hiddenDownloader";
iframe.style.visibility = 'hidden';
iframe.src = "api.php";
http.open("GET", "api.php");
document.body.appendChild(iframe);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.responseText != '') {
rslt = http.responseText;
document.getElementById('gw_content').innerHTML = rslt;
first_time = '';
}
// http.onreadystatechange = function(){};
// http.abort();
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
function getWidget() {
$('#myModal').modal('show');
}
</script>
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<b style="color: #000;">Modal</b>
</div>
<div class="modal-body">
<h4>Modal</h4>
<p>Instructions...</p><br />
<div id="gw_content">
<body onload="doauth();" />
<img src="wheel-throb.gif">
</div>
</div>
</div>
<button type="button" onclick="getWidget();">Open</button>