HTML/Javascript Connection Webservice C#

Asked

Viewed 742 times

0

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

I even set up an example where I created the functions sum and multiply in my Webservice, but I’m having difficulty connecting my (HTML/Javascript) in my Webservice (C#).

I found several examples on the Internet, but none of them could resolve my doubts, for this reason I decided to ask here to see if someone could help me make this communication of Webservice with my HTML.

I need my HTML and Javascript to be separate from a web application because I want to use it (after understanding how communication works) phonegap to make requests to the database 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 phonegap and access a webservice to request data that comes from the bank and load them in the app.

  • The way you explained it wasn’t very clear... you came to make some code?

1 answer

1

Regardless of the back-end language used to communicate with JS/HTML you must use a REST service, that is your application must 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 have something like this:

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

by accessing this url your service should return something like:

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

With jQuery you will do on a page http://webservice.meusite.com.br/teste.html:

$.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 console output.

If you will use the request $.ajaxon a different domain you should use JSONP

  • In this case I am using C# as a web service, but when I get the Response, I get the following error : Uncaught Syntaxerror: Unexpected token <

  • If the JS error is probably a character being printed in the wrong place in JSON. You can paste your JSON output into http://jsfiddle.net/ ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.