[英]Phonegap/Android error: Uncaught ReferenceError: url is not defined at file:///android_asset/www/js/login.js:17
I created a phonegap app for Android and i put the login "logic" into a javascript file. 我为Android创建了一个phonegap应用,并将登录名“逻辑”放入了一个javascript文件。 Somethimes the login function works, sometimes it doesn't.
有些功能登录功能有效,有时则无效。 When it doesn't, i get the following error:
如果没有,则出现以下错误:
10-24 10:01:13.211: Web Console(25080): Uncaught ReferenceError: url is not defined at file:///android_asset/www/js/login.js:17
10-24 10:01:13.211:Web控制台(25080):未捕获的ReferenceError:在文件:///android_asset/www/js/login.js:17中未定义url
Everything is there and when i used cordova2.0.0 it was working fine, but i had to switch to cordova 2.1.0. 一切都在那里,当我使用cordova2.0.0时,它工作正常,但是我不得不切换到cordova 2.1.0。 Since the switch it doesn't always work fine.
由于开关,它并不总是可以正常工作。 Here's how i include the resources in the html file:
这是我在html文件中包含资源的方式:
<html>
<head>
<title>Hello World</title>
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<link rel="stylesheet" href="css/jquery.mobile-1.1.1.min.css" />
<script type="text/javascript" src="js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/login.js"></script>
</head>
...
here's my login.js 这是我的login.js
$('#page_login_submit').live('click',function(){
var name = $('#page_login_name').val();
if (!name) { alert('Please enter your user name.'); return false; }
var pass = $('#page_login_pass').val();
if (!pass) { alert('Please enter your password.'); return false; }
$.ajax({
url: "http://scoreboard.pronovix.net/?q=scoreboard/user/login.json",
type: "POST",
data: 'username=' + encodeURIComponent(name) + '&password=' + encodeURIComponent(pass),
dataType: "json",
error: function(jqXHR, textStatus, errorThrown) {
alert('Login fail: ' + url + '+' + data); //that's line 17
console.log(JSON.stringify(jqXHR));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
window.location.href = 'index.html';
}
});
return false;
});
Can anyone tell the reason why? 谁能说出原因?
Any help is very much appreciated! 很感谢任何形式的帮助!
Sincerely, 真诚的
Zoli 佐利
You are trying to reference the url variable to print out in your error but you have not defined it anywhere. 您正在尝试引用url变量以在错误中打印出来,但尚未在任何地方定义它。
Remember the error function does not have access to the parameters of the ajax function. 请记住,错误函数无法访问ajax函数的参数。
Possible solution 可能的解决方案
If you implement the beforeSend function you can save the url then use it later 如果实现了beforeSend函数,则可以保存该URL,然后在以后使用
beforeSend: function (jqXHR, settings) {
url = settings.url + "?" + settings.data;
}
This solution was taken from Access the URL of an jQuery Ajax Request in the Callback Function 此解决方案取自在Callback函数中访问jQuery Ajax请求的URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.