我一直在试图使用来自一个PhoneGap的,Android应用程序写在ASP.NET Web服务,但我似乎犯了一个错误莫名其妙的地方。
Hi, i've been trying to consume a Web Service written in ASP.NET from a phonegap-android app but i seem to be making a mistake somehow somewhere.
值得一提的是,这个失败,当我从Eclipse中的Android模拟器中运行它。我已经尝试从Web浏览器相同的code和它工作得很好。
It's worth mentioning that this fails when i run it on the android emulator from eclipse. I've already tried the same code from a web browser and it works just fine.
以下是部分的的index.html 的这相关的问题
Here's the part of Index.html that's relevant for the question
/* Here i declare 'webServiceURL' which holds the path to the service that's
hosted at 10.0.0.174 (WLAN ip of my computer). I use this instead of 127.0.0.1
because on a mobile phone localhost points to the phone itself. */
// Here i declare 'datos' which are the parameters sent to the web service method
$.ajax({
url: webServiceURL + "InicioSesion",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(datos),
dataType: 'json',
beforeSend: function() {$.mobile.loading('show')},
complete: function() {$.mobile.loading('hide')},
success: function (data, textStatus, jqXHR) {
// Here i do stuff with 'data'
},
error: function (jqXHR, textStatus, errorThrown) {
// Here i print errors
},
)};
访问权限原产地加入到PhoneGap的的的config.xml 的
<access origin="*"/>
修改到的的web.config 的ASP.NET Web服务的
Modifications to the web.config of the ASP.NET Web Service
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
我要面对错误是,当我设置的dataType到JSON(这是我期待)Ajax请求失败,并打印textStatus'给我的 ParserERROR 的
所以,我想用'的dataType作为文,而不是JSON,看看是否有什么错误的Web服务的响应,我意识到,问题是,反应是NULL。
So i tried using 'dataType' as 'text' instead of 'json' to see if there was something wrong with the Web Service response, and i realized that the problem was that the response was NULL.
记得我提到的,这个code完美的作品上的Web浏览器,它无法在PhoneGap的应用程序在Android模拟器中运行。
REMEMBER what i mentioned, this code works perfectly on a Web Browser, it fails on the phonegap app running from the android emulator.
如果有人带着几分使用PhoneGap的消费ASP.NET Web服务的经验可以请帮助我!我不知道我失踪或者做错了什么!我一直在这2天,现在我只是无法找到解决的办法!
If anybody with a bit of experience using phonegap to consume an ASP.NET Web Service could please help me!. I have no idea of what i'm missing or doing wrong!. I've been working on this for 2 days by now and i just can't find a solution!
我已经想通了这个错误我是做!
在访问权限原产地加入到PhoneGap的的的config.xml 的我把:
On the access origin permission added to phonegap config.xml i was putting:
<access origin="*"/>
这是不正确的!正确的方式把它与一个点('。')星号之前(*):
That's incorrect!, the right way to put it is with a dot ('.') before the asterisk ('*'):
<access origin=".*"/>
这就是它!问题解决了!
上一篇:安卓:片段时,SQLite和装载机装载机、片段、SQLite
下一篇:更换TabActivity与FragmentActivity和片段片段、TabActivity、FragmentActivity