Search code examples
asp.netapachecordovaasmxvisual-studio-2015

Visual Studio 2015 Server side with Cordova Apache


I hope this question is concrete.

I want to create a cross-platform mobile application. In order to do so I have decided I will probably use an IDE that will support Apache Cordova. I have decided I will probably use Visual Studio 2015 with Additional Tools For Apache Cordova.

The main concern I have is regarding the server side connection I need to have in my future application. I have some MS-SQL Tables that I want to get access to via this application. As far as I understood, Apache Cordova projects consist only pure JS and HTML. In the past I have used ASPX/ASMX extensions in order to communicate with my database. Is there an alternative? Or can I just use the good old ASMX Web Service inside an Apache Cordova project and it will still work cross-platform?

Thanks for any light on that matter!


Solution

  • You are right,

    Apache Cordova/Phonegap projects consist only pure JS and HTML (and CSS)

    Cordova/Phonegap is just a wrapper, it wraps your page in a container and provide the necessary APIs to communicate with the device's features.

    So the only way to communicate to a server side method in another place/project is by calling a web service, you can perform an asynchronous HTTP (Ajax) request like this

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: "http://yourSite/yourApp/YourWebService.asmx/methodName",
        data: JSON.stringify({firstField: 123}),
        success: function (msg) {
            alert('It Works!');
        },
        error: function (xhr, status, error) {
            alert('It does not work!');
        }
    });
    

    Probably you could find issues with cross-domain calls, it means that you can't call web services on the client from a domain that is not the web service's domain.

    I recommend to use a pure JavaScript CORS alternative, xDomain; I have used and it really works for the cross-domain issues, also it has a nice examples and explains very well how to use it