【发布时间】:2015-11-11 06:50:32
【问题描述】:
我在我的项目中使用以下 AJAX
var _getWeatherInfo = function(ntown){
//Debugging
console.log("Before dojo.xhrget");
//dojo ajax request used to call the PHP file and retrieve the towns data
dojo.xhrGet({
handleAs: "json",
timeout: 5000,
//php file URL (location)
url: "PHP/weather.php?ntown=" + ntown,
load: function(results) {
//send the results to the function _refreshWeatherList
_refreshWeatherList(results);
}
});
//Debugging
console.log("After dojo.xhrget");
}
为了检索城市/城镇的天气数据。但是,自从我从事这个项目以来已经有一段时间了,我无法理解为什么它不再起作用(我上次运行这个项目时它还在起作用)。
在浏览器控制台中我收到以下错误:
SyntaxError: Unexpected token <
at Object.b.fromJson (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:227:426)
at Object.b._contentHandlers.b.contentHandlers.json (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:185:216)
at t (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:189:392)
at c (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:75:221)
at d (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:75:10)
at resolve.callback (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:76:350)
at http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:192:378
at k (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:196:406)
at n (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:196:332)
at resolve (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:198:406)y @ dojo.js.uncompressed.js:14021(anonymous function) @ dojo.js.uncompressed.js:13981c @ dojo.js.uncompressed.js:4579d @ dojo.js.uncompressed.js:4560reject.errback @ dojo.js.uncompressed.js:4655c @ dojo.js.uncompressed.js:4594d @ dojo.js.uncompressed.js:4560reject.errback @ dojo.js.uncompressed.js:4655c @ dojo.js.uncompressed.js:4590d @ dojo.js.uncompressed.js:4560resolve.callback @ dojo.js.uncompressed.js:4640(anonymous function) @ dojo.js.uncompressed.js:14208k @ dojo.js.uncompressed.js:14488n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14503n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14509n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14503n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643r @ dojo.js.uncompressed.js:11883f @ dojo.js.uncompressed.js:11909
我包括道场使用:
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
xhr 响应:
"<!--Include Database connections info-->
↵
↵↵( ! ) 已弃用:mysql_connect():mysql 扩展已弃用,将来将被删除:在 E:\Program Files (x86)\wamp\www\ 中使用 mysqli 或 PDO 代替Weather-Widget-App-master\PHP\configHome.php 上线 6↵Call Stack↵#TimeMemoryFunctionLocation↵10.0004244528{main}( )..\weather.php: 0↵20.0006248360include('E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php')..\weather.php:2↵ 30.0006248936http://www.php.net/function.mysql-connect' target='_new'>mysql_connect↵( )..\configHome.php:6↵↵
↵↵( ! ) 警告:mysql_select_db() 期望参数 1 是字符串,资源在 E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php 行 9↵调用堆栈↵#TimeMemoryFunctionLocation↵10.0004244528{main}()..\weather.php:0↵20.0006248360include('E:\Program Files (x86)\wamp\www\Weather -Widget-App-master\PHP\configHome.php')..\weather.php:2↵30.0300257280http://www.php.net/function. mysql-select-db' target='_new'>mysql_select_db↵( )..\configHome.php:9↵↵在 mysql 服务器上选择指定数据库时出错:"
【问题讨论】:
-
xhr 请求是否收到响应?你能贴出来吗?我想知道您的服务器是否返回格式错误的 json。
-
听起来服务器响应的是 XML 而不是 JSON
-
抱歉回复晚了。我做了一些进一步的工作,并在 xhr 回复中找到了一些有用的信息(感谢 Russell 的建议!)。
-
更新:从 xhr 响应来看,我的 SQL 连接/语句显然有一些错误。现在都修好了。感谢您的帮助。
标签: javascript ajax dojo