我有一个完全可操作的ASP.NET Webform应用程序(.aspx),它使用jQuery AJAX向服务器(CodeBehind)发送和检索数据。对于我的下一个项目,我需要重新创建这个应用程序,但使用Phonegap使其具有移动性和平台独立性。
我正在尝试使用处理数据库连接的同一个CodeBehind文件以及使应用程序正常工作所需的所有方法。
// File-structure
Application
App_Code
pages
Default.aspx (with codebehind)
phonegapapp
www
- index.html (with jquery AJAX calls)
...我正在尝试从index.html文件连接到Default.aspx.cs文件,以访问必要的功能:
// phonegapapp/www/index.html
$(function () {
$.ajax({
type: "POST",
...
url: "../../Default.aspx/testFunction",
// tried with only one ../ and going to root and follow file structure but non is working.
...
});
});我收到一个错误,显示找不到该文件:
XMLHttpRequest cannot load file:///C:/Application/pages/Default.aspx.cs/testFunction. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.发布于 2016-01-11 03:50:28
你不能在phonegap应用程序中执行/访问aspx文件。您只需将aspx文件放在支持get服务器的Asp.Net后面,然后加载带有相对路径的调用ajax,如http://localhost/default.aspx,然后您就可以获得响应。
https://stackoverflow.com/questions/31029243
复制相似问题