我有一个非常简单的应用程序,我只需要在iOS和Android上测试一些功能。 代码是一样的。 这是非常简单的代码(PhoneGap 3.6.3-0.22.1骨架项目):
<!DOCTYPE html>
<!--
Copyright (c) 2012-2014 Adobe Systems Incorporated. All rights reserved.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.soap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
相关的JS部分是以下一部分,在deviceready
事件被触发后调用:
soapTest: function() {
console.log("going to authenticate!");
$.soap({
url: 'http://<my_url>/api/?wsdl',
method: 'login',
data: {
username:'<user_here>',
apiKey:'<api_key_here>'
},
success: function (soapResponse) {
console.log("Success");
},
error: function (SOAPResponse) {
console.log("Fail");
}
});
}
我在SO中看到了很多类似的问题,但是这里有些奇怪的是这段代码在iOS模拟器中工作(“成功”),但它不适用于Android(“失败”)。
请注意,我在每个config.xml文件中都有<access origin="*" />
行,一般文件和特定于平台的文件。
在jquery.soap.js库中进行调试,这是Android中的SOAP响应:
11-18 05:03:49.410: I/chromium(889): [INFO:CONSOLE(387)] "{"readyState":0,"responseText":"","responseXML":null,"status":0,"statusText":"error"}", source: file:///android_asset/www/js/jquery.soap.js (387)
任何提示?感谢。