简体   繁体   English

在Phonegap应用程序中将数据从jQuery AJAX发送到ASP.NET

[英]Send data from jQuery AJAX to ASP.NET in Phonegap application

I have a fully operational ASP.NET Webform application (.aspx) that sends and retrieves data to the server (CodeBehind) using jQuery AJAX. 我有一个完全可操作的ASP.NET Webform应用程序(.aspx),它使用jQuery AJAX发送和检索数据到服务器(CodeBehind)。 For my next project I need to recreate this application but with Phonegap to make it mobile and platform independent. 对于我的下一个项目,我需要重新创建此应用程序,但要使用Phonegap使其移动和独立于平台。

I'm trying to use the same CodeBehind file that handles the database connection and all the needed methods to make the application work. 我正在尝试使用相同的CodeBehind文件来处理数据库连接以及使应用程序正常工作所需的所有方法。

// File-structure

Application
    App_Code
    pages
        Default.aspx (with codebehind)
        phonegapapp
            www
            - index.html (with jquery AJAX calls)
    ...

From the index.html file I'm trying to make a connection to the Default.aspx.cs file to access the necessary functions: 我正在尝试从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.
        ...
    });
});

I get an error showing that the file is not found: 我收到一条错误消息,表明找不到该文件:

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.

You cant execute/access aspx files wihtin phonegap app. 您无法通过phonegap应用程序执行/访问aspx文件。 Simply you have to put your aspx files behind an Asp.Net supporting webserver such as IS and then you load call ajax with relative path, like http://localhost/default.aspx and then you will be able to get the response. 只需将aspx文件放在支持Asp.Net的网络服务器(例如IS)之后,然后使用相对路径(例如http://localhost/default.aspx)加载调用ajax,然后就可以获取响应。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM