PhoneGap 用のモバイル アプリを作成しています。自分で作成した ASP.NET Web サービスを介して外部データを読み込もうとしています。Ripple Emulator でローカルを実行し、URL をローカル Web サービスに設定すると、Web サービスは正しく動作します。URL をオンライン バージョンに変更した瞬間、クロスプラットフォームなので、ローカルの Ripple Emulator では機能しなくなり、次のエラーが表示されます。
SyntaxError: Unexpected token e
at Object.parse (native)
at IncomingMessage.module.exports (/app/node_modules/express/node_modules/connect/lib/middleware/json.js:76:27)
at IncomingMessage.EventEmitter.emit (events.js:93:17)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
at Socket.socket.ondata (http.js:1825:22)
at TCP.onread (net.js:404:27)"
オンラインで考えられる解決策をたくさん読みましたが、問題を解決できないようです。Phonegap、jQueryMobile、および Web サービスを読んだ後、これは単純なものであり、JSONP、プロキシ、HttpHandlers などのソリューションがなくても機能するはずだと思いました。
以下に、関連するはずのコードをいくつか追加しました。
HTML/JAVASCRIPT
function onBodyLoad() {
// Add the PhoneGap deviceready event listener
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
// Test the function
login();
}
function login() {
try {
// Validate credentials
$.ajax({
type: "POST",
url: 'http://login.multiviewer.nl/Mobile.asmx/ValidateCredentials',
contentType: "application/json; charset=utf-8",
data: '{ username: "x", password: "y", browser: "", title: "", ipAddress: "" }',
dataType: "json",
success: function (object) {
alert("success");
},
error: function (em, msg) {
alert("function error");
}
});
}
catch (err) {
alert("catch error");
}
}
//-->
</script>
ASP.NET Web サービス ASMX
namespace Web.Core.WebServices
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Mobile : WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ValidateCredentials(string username, string password, string browser, string title, string ipAddress)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();
keyValues.Add("Something", "Ok");
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Serialize(keyValues);
}
}
}
フォンギャップ
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.multiviewer.app" version="1.0.1" versionCode="1">
<!-- General app settings -->
<name>App name</name>
<description>App description</description>
<author href="http://www.rhainesoft.nl/" email="info@rhainesoft.nl">RhaineSoft</author>
<!-- App icon -->
<icon src="images/icon.jpg" />
<!-- Features used, rights needed at installing -->
<preference name="permissions" value="none"/>
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<!-- Expose access to all URIs, including the file and http protocols -->
<access origin=".*"/>
<!-- Content -->
<content src="index.html" />
</widget>
この問題を解決するための助けに感謝します。ご不明な点がございましたら、または何か見逃した場合はお知らせください。