Software Archive
Read-only legacy content
17061 Discussions

How can I call a Web Service?

Melike_K_
Beginner
1,475 Views

Hi,

I create a web service and I want to call its from my file.js. How can I do it? When I press an enter button the webservice is run again(and take my parameter that for web service like user name and password). Actually I want to send parameter to my web service in the same time. Is it possible? If yes, How can I do it? I search on th enternet but cannot find an answer  for my question.

0 Kudos
13 Replies
Brandon_K_Intel
Employee
1,475 Views

1.) How did you build your application? (App Designer or did you hand code your project)

2.) What is the web service you are trying connect to? (Facebook, twitter, own server, etc.)

0 Kudos
Chris_P_Intel
Employee
1,475 Views

If you made the service data binding with the Web Services control, then the name you gave the service is a function ready to call. It is in the intel.xdk.services namespace.  

For example:

intel.xdk.services.MarkitOnDemandQuote()

 

This will call the service, which returns a promise for its data. There is also an event with the same name as the service posted to the document.  

Penultimately, if you have custom arguments, just pass them in an options.  For example:

//get the result via a promise
intel.xdk.services.MarkitOnDemandQuote({symbol:"INTC"})
.then(function(data){ 
    console.log("here is the data from the service", data); 
})


//or get the result via na event

$(document).on("intel.xdk.services.MarkitOnDemandQuote", function(evt, data){ 
  console.log("event received. here is the data", data); 
})
intel.xdk.services.MarkitOnDemandQuote({symbol:"AAPL"); //will trigger the event

Lastly, if you want to _modify_  the data before any consumer sees it, you can pass in an xdkFilter: argument to the options. It is a function that will receive the raw data, and whatever it returns will be the data that is passed out through the promise or the event.  

0 Kudos
Rodrigo_M_1
New Contributor II
1,475 Views

Hello, follow a simple example how to call a WebService... you can put it on your own javascript file, reference it on your HTML5 code and call this function:

 

function CallWebService() { 
    $.ajax('http://YourWebServiceLink', {    
    contentType: 'text/xml; charset=utf-8',
   dataType: 'xml',
    crossDomain: true,    
   data: {
        pUserName : 'YourUserName',
        pPassWord : 'YourPassword'
   },
   success: function(data) { 
           var vSomeColumn01 = $(this).find("SomeColumn01").text();
           var vSomeColumn02 = $(this).find("SomeColumn02").text();
           var vSomeColumn03 = $(this).find("SomeColumn03").text();
           var vSomeColumn04 = $(this).find("SomeColumn04").text();           
       });
   },   
        error: function (data) {  
        	alert($(data).text);
        }
});
}

 

0 Kudos
Melike_K_
Beginner
1,475 Views

CHRIS P. (Intel) wrote:

If you made the service data binding with the Web Services control, then the name you gave the service is a function ready to call. It is in the intel.xdk.services namespace.  

For example:

intel.xdk.services.MarkitOnDemandQuote()

 

This will call the service, which returns a promise for its data. There is also an event with the same name as the service posted to the document.  

Penultimately, if you have custom arguments, just pass them in an options.  For example:

//get the result via a promise
intel.xdk.services.MarkitOnDemandQuote({symbol:"INTC"})
.then(function(data){ 
    console.log("here is the data from the service", data); 
})


//or get the result via na event

$(document).on("intel.xdk.services.MarkitOnDemandQuote", function(evt, data){ 
  console.log("event received. here is the data", data); 
})
intel.xdk.services.MarkitOnDemandQuote({symbol:"AAPL"); //will trigger the event

Lastly, if you want to _modify_  the data before any consumer sees it, you can pass in an xdkFilter: argument to the options. It is a function that will receive the raw data, and whatever it returns will be the data that is passed out through the promise or the event.  

 

Firstly thank you for your answer. As I understand, you send to me two piece of code that I can use in my project and I can choose one of them, isn't it? and I have a few questions:

1) What is the mean of "INTC" at "...intel.xdk.services.MarkitOnDemandQuote({symbol:"INTC"})..." ? What can I put instead of INTC? "symbol" is a variable or not? If yes what can I put instead of it? (and mean of "AAPL"?)

2) 

.then(function(data){
04     console.log("here is the data from the service", data);
05 })

this function is my web services function, isn't it? and "data" is my returning value? If I want to send two parameter I must do like follow?

.then(function(userName, password,data){
04     console.log("here is the data from the service", data);
05 })

 

Thank you...

0 Kudos
Melike_K_
Beginner
1,475 Views

Rodrigo M. wrote:

Hello, follow a simple example how to call a WebService... you can put it on your own javascript file, reference it on your HTML5 code and call this function:

 

function CallWebService() { 
    $.ajax('http://YourWebServiceLink', {    
    contentType: 'text/xml; charset=utf-8',
   dataType: 'xml',
    crossDomain: true,    
   data: {
        pUserName : 'YourUserName',
        pPassWord : 'YourPassword'
   },
   success: function(data) { 
           var vRecID = $(this).find("SomeColumn01").text();
           var vMake = $(this).find("SomeColumn02").text();
           var vModel = $(this).find("SomeColumn03").text();
           var vYear = $(this).find("SomeColumn04").text();           
       });
   },   
        error: function (data) {  
                    alert($(data).text);
                }
});
}

 

 

thank you but I don't want to reach my services with url. I want to reach it with web services that I created in intel xdk.

11_0.png

0 Kudos
Melike_K_
Beginner
1,475 Views

Brandon Kiefer (Intel) wrote:

1.) How did you build your application? (App Designer or did you hand code your project)

2.) What is the web service you are trying connect to? (Facebook, twitter, own server, etc.)

1) I built my application with app designer and hand code. I firstly built it with app designer and then I built with hand code somewhere that I cannot do it with app designer.

2)I try to connect with I created new services. it is business' web site.

0 Kudos
Melike_K_
Beginner
1,475 Views
The other words my problem is like that:


<script>
            
            function Control(){
                var MINLENGTH = 3;
                var formUsername = document.forms.login.e_posta.value;
                var formPassword = document.forms.login.password.value;

                    //is that true??????????????????????????????????
                    intel.xdk.services.LNLAyatar3Bolge({symbol:"INTC"})
                    .then(function(data){
                        console.log("here is the data from the service", data);
                        alert(data);
                        alert("cefdvefv");
                    })
                    return;
            }
</script>

 

 

My piece of code is upside. I take the username(formUsername) and user password(formPasword) from user. And then I click the my ENTER button. When I click the ENTER button I call this script code. I want to this code run like that Call the my web services and send the formUsername annd fromPassword to web service(or my web service's data binding).

0 Kudos
Chris_P_Intel
Employee
1,475 Views

In my example, {symbol:"INTC"} is data that a specific service was looking for.  It was just example data.

Think of it as {search:"puppies"}  for an image searching service

0 Kudos
Chris_P_Intel
Employee
1,475 Views

If you look at your web service in App Designer (in the "Service Methods" pane, you'll see there are two description panes for it: "Request" an d "Response".  Request the parameters your service expects.

So you can use _those_ instead of "symbol".  Let's pretend one parameter is "user" and the other "password".  Then your code would look like this:

function Control(){
                var MINLENGTH = 3;
                var formUsername = document.forms.login.e_posta.value;
                var formPassword = document.forms.login.password.value;
 
                    
                    intel.xdk.services.LNLAyatar3Bolge({name:formUsername, password:formPassword})
                    .then(function(data){
                        console.log("here is the data from the service", data);
                        alert(data);
                        alert("cefdvefv");
                    })
                    return;
            }

 

0 Kudos
Melike_K_
Beginner
1,475 Views

 

Thank you so much all of you for all your answers and 

CHRIS P. (Intel) wrote:
, you help me understanding web services logic. 

Have a nice day :))

0 Kudos
Ricardo_C_1
Beginner
1,475 Views

My webservice is simple, IK call it as a PHP in a server, the php do the job on a wsdl webservice and returme a JSON object, like in the developer, I can get this JSON return, and assign the columns I want to put in a control like a ListView ?

 

Thanks in advance !

0 Kudos
Nick_F_2
New Contributor III
1,475 Views

In your app.js from the results of your JSON build a string containing HTML listview and then display it on a named <div></div> placed on your page in the desired location.

0 Kudos
Ricardo_C_1
Beginner
1,475 Views

I can do it directly ?

I can populate the ListView Objectg in the code ?

 

Thank you again

 

0 Kudos
Reply