HTML / JavaScript Connection WebService C #

0

I'm trying to make a connection to the bank using web service.

I came up with an example where I created the sum and multiply functions in my WebService, but I'm having difficulty connecting my (HTML / JavaScript) to my WebService (C #).

I found several examples on the internet, but none of them could resolve my doubts, so I decided to ask here to see if anyone could help me make this WebService communication with my HTML.

I need my HTML and Javascript to be separated from a web application because I want to use (after understanding how communication works) phonegap to make requests to the bank and return the values to the user.

I do not know if I could be very clear, but my idea is to have an app compiled in the phonegap and in it access a webService to request data coming from the bank and upload them in the app.     

asked by anonymous 06.06.2014 / 21:34

1 answer

1

Regardless of the back-end language used to communicate with JS / HTML you must use a REST service, ie your application should return a JSON to any request made through JS.

Let's imagine that your webservice is configured to receive SQL via query string (beware of the data that is released by your webservice for security reasons), so we'll have something like this:

http://webservice.meusite.com?query=SELECT%20*%20FROM%20user
(http://webservice.meusite.com?query=SELECT * FROM user)

accessing this url your service should return something like:

{
    users:[
        {
            nome: "João",
            email: "[email protected]"
        },
        {
            nome: "maria",
            email: "[email protected]"
        },
        {
            /*...*/
        },
    ]
}

With jQuery you'll do it on a link page:

$.ajax({
    url: "http://webservice.meusite.com?query=SELECT%20*%20FROM%20user",
    success : function(data){
        for(var i in data.users)
            console.log(data.users[i].nome);
    }
});

See the output on the console.

If you are going to use the $.ajax request in a different domain you should use JSONP

    
08.06.2014 / 16:08