简体   繁体   中英

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. For my next project I need to recreate this application but with Phonegap to make it mobile and platform independent.

I'm trying to use the same CodeBehind file that handles the database connection and all the needed methods to make the application work.

// 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:

// 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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