Click to See Complete Forum and Search --> : call web service in javascript


john_zakaria
05-03-2010, 05:14 AM
i have a web service at this url http://196.218.16.133/onlinereservation/service.asmx?op=HotelsSearch

i use hotel search file with HotelSearch method and method will retrieve xml file contains the matched data.

the varialbe that i made post with it is named : HotelData

the data of the variable is a string file that contains an xml data like this
<HotelsParameters>
<CityID>388</CityID>
<UserName>admin</UserName>
<UserPassword>admin</UserPassword>
<DateFrom>4/12/2010</DateFrom>
<DateTo>4/13/2010</DateTo>
<NumberOfRooms>2</NumberOfRooms>
<Room>
<RoomSerial>1</RoomSerial>
<Adults>1</Adults>
<Child>
<ChildSerial>1</ChildSerial>
<ChildAge>5</ChildAge>
</Child>
</Room>
<Room>
<RoomSerial>2</RoomSerial>
<Adults>2</Adults>
<Child>
<ChildSerial>1</ChildSerial>
<ChildAge>8</ChildAge>
</Child>
</Room>
<Room>
<RoomSerial>3</RoomSerial>
<Adults>3</Adults>
<Child>
</Child>
</Room>
<CurrencyID>162</CurrencyID>
</HotelsParameters>

i am trying to get the result by posting HotelData but i did not get the xml result file
so can anyone help me
my code is:

<script language="JavaScript">
function InitializeService() {
service.useService("http://196.218.16.133/onlinereservation/service.asmx?WSDL", "HotelsSearch");
}
var StrSearch;
function GetAge() {
StrSearch = document.DemoForm.StringSearch.value;

service.HotelsSearchService.callService("HotelsSearch", StrYear);
}
function ShowResult() {
alert(event.result.value);
}
</script>
<form name="DemoForm">
Hotel Name : <input type="text" name="HotelData"/><br />
<button onclick="GetAge()">Get Data</button>
</form>


the data in input filed is the previous xml file

sohguanh
05-13-2010, 03:49 AM
i have a web service at this url http://196.218.16.133/onlinereservation/service.asmx?op=HotelsSearch


<script language="JavaScript">
function InitializeService() {
service.useService("http://196.218.16.133/onlinereservation/service.asmx?WSDL", "HotelsSearch");
}
var StrSearch;
function GetAge() {
StrSearch = document.DemoForm.StringSearch.value;

service.HotelsSearchService.callService("HotelsSearch", StrYear);
}
function ShowResult() {
alert(event.result.value);
}
</script>
<form name="DemoForm">
Hotel Name : <input type="text" name="HotelData"/><br />
<button onclick="GetAge()">Get Data</button>
</form>


the data in input filed is the previous xml file

May I know the variable "service" is a JavaScript class ? It have methods called useService, HotelsSearchService ?

You deploy a Web Service so is it using SOAP ? If yes then according to SOAP, you need to have some Envelope Header followed by Body and an optional Fault. The Body is where you put and retrieve the data. You can write your own or look for a SOAP JavaScript class to help you.

It is the same as JavaScript issue AJAX call. If the server end mandate JSON, then when you call and retrieve the response from the server, you need a JSON parser to extract the data. In this case the server end "talk" JSON and not SOAP.

And now there are REST-ful Web Service. It is amazing isn't it! So many new/modified/re-hashed ideas/concepts from IT industry. I swear by the phrase "The only constant is change in IT software development arena" :D

PS I haven't get into a discussion on RPC, DCOM and CORBA which should be fading away nowadays.