简体   繁体   English

Cordova中的本地Web服务调用失败,结果为ERR_FILE_NOT_FOUND

[英]Local web service call in Cordova fails with result ERR_FILE_NOT_FOUND

I am using ASP.Net and building an android app using Cordova 5.1.1. 我正在使用ASP.Net并使用Cordova 5.1.1构建一个Android应用程序。 I have created the web service ( services.asmx ) which has a method appStatus and I am calling the same in index.html page. 我创建了具有方法appStatus的Web服务( services.asmx ),并在index.html页面中调用了该服务。 This works perfectly when I run or publish in my laptop. 当我在笔记本电脑上运行或发布时,此功能非常理想。 But once I build and run, I get the file not found error with status 0. 但是一旦构建并运行,我会收到状态为0的文件未找到错误。

Ajax Call 阿贾克斯电话

        var request = $.ajax({
            url: "services.asmx/appStatus",
            method: "POST",
            data: {},
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: ajaxSigninSuccess,
            error: ajaxSigninError
        });

        function ajaxSigninSuccess(response) {
            alert(response.d);
        }

        function ajaxSigninError(response) {
            alert(response.status + " " + response.statusText);
        }

Following is the response text 以下是回复文字

onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: null
onreadystatechange: null
ontimeout: null
readyState: 4
response: ""
responseText: ""
responseType: ""
responseURL: ""
responseXML: null
status: 0
statusText: ""
timeout: 0

Error 错误

GET file:///android_asset/www/services.asmx/appStatus net::ERR_FILE_NOT_FOUND

Please help, thanks in advance. 请帮助,在此先感谢。

You have problem about server + client side. 您对服务器+客户端有疑问。
I call server is where your service ASP.Net ("services.asmx") deploy. 我称服务器是您的服务ASP.Net(“ services.asmx”)部署的位置。
Client is your mobile app in device. 客户端是您在设备中的移动应用。

1. When your server + client in your computer. 1.当服务器+客户端在计算机中时。
Ex: url service: " http://localhost:8080/services.asmx " then when you call ajax by url 'services.asmx/appStatus' then it will get path of html file(include ajax code) and prepend to url. 例如:url服务:“ http:// localhost:8080 / services.asmx ”,那么当您通过url'services.asmx / appStatus'调用ajax时,它将获取html文件的路径(包括ajax代码)并添加到url之前。 If html file is " http://localhost:8080/index.html " then url call by ajax will be: " http://localhost:8080/services.asmx/appStatus ". 如果html文件是“ http:// localhost:8080 / index.html ”,那么ajax的url调用将是:“ http:// localhost:8080 / services.asmx / appStatus ”。 I think it working with you. 我认为它与您合作。

2. When server deploy in you computer and client running in device (emulator). 2.当服务器部署在计算机中并且客户端运行在设备(仿真器)中时。
Ip address of your computer and emulator in your computer is different. 您的计算机的IP地址和计算机中的模拟器是不同的。 Your app start with index.html file: "file:///android_asset/www/index.html" and so that url call by ajax will be: "file:///android_asset/www/services.asmx/appStatus" not found any service or file at url. 您的应用以index.html文件开头:“ file:///android_asset/www/index.html”,因此,ajax调用的网址为:“ file:///android_asset/www/services.asmx/appStatus”在网址找到任何服务或文件。

3. Solutions: call ajax by full url: " http://domain.com/services.asmx/appStatus " or if your server deploy in local then " http://ipaddress:port/services.asmx/appStatus ". 3.解决方案:通过完整URL调用ajax:“ http://domain.com/services.asmx/appStatus ”,或者如果您的服务器部署在本地,则“ http:// ipaddress:port / services.asmx / appStatus ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sencha Cordova Android ERR_FILE_NOT_FOUND(与sencha Web目录一起部署在tomcat实例上的API) - Sencha Cordova Android ERR_FILE_NOT_FOUND (API deployed on tomcat instance along with sencha web dir) 无法使用Cordova加载资源:net :: ERR_FILE_NOT_FOUND - Failed to load resource: net::ERR_FILE_NOT_FOUND with Cordova Phonegap/Cordova 应用程序错误网络::ERR_FILE_NOT_FOUND - Phonegap/Cordova Application Error net::ERR_FILE_NOT_FOUND AngularJS 2和Cordova:“无法加载资源:net :: ERR_FILE_NOT_FOUND” - AngularJS 2 and Cordova: “Failed to load resource: net::ERR_FILE_NOT_FOUND” 正在获取ERR_FILE_NOT_FOUND - Getting ERR_FILE_NOT_FOUND Android Studio(网页帮助)网:ERR_FILE_NOT_FOUND - Android Studio (Web page help) net : ERR_FILE_NOT_FOUND 科尔多瓦| ERR_FILE_NOT_FOUND(文件:///android_assets/www/index.html) - Cordova | ERR_FILE_NOT_FOUND(file:///android_assets/www/index.html) 科尔多瓦网::ERR_FILE_NOT_FOUND(file:///android_assets/www/) - Cordova net::ERR_FILE_NOT_FOUND(file:///android_assets/www/) Webview 网页不可用 ERR_FILE_NOT_FOUND - Webview Webpage not available ERR_FILE_NOT_FOUND 使用本地HTML在Android上加载本地文件-net :: ERR_FILE_NOT_FOUND - Loading Local Files on Android With Local HTML - net::ERR_FILE_NOT_FOUND
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM