Jquery,Ajax වලින් Web Service එක Access කරන්න බැ. හදා ගන්නේ කොහමද??
Jquery,Ajax වලින් Web Service එක Access කරන්න බැ. හදා ගන්නේ කොහමද??
මම දැනට වෙබ් එකක් හදනවා. එක Data ගන්නේ SOAP Web Service එකකින්. අදාල Inputs ලබා දිලා , Search එක ක්ලික් කරාම , වෙබ් බ්රව්සර් එකේ Console Tab එකේ "
ඒත් මට ඕන Extension භාවිතා නොකර මේක හදා ගන්නේ කොහමද කියල දැන ගන්නයි. උදව් කරන්න පුලුවන් නම් ලොකු දේයක්.
මේ පහල විධියට තමයි , Request එක යවන්නේ.
Jquery,Ajax වලින් Web Service එක Access කරන්න බැ. හදා ගන්නේ කොහමද??
මම දැනට වෙබ් එකක් හදනවා. එක Data ගන්නේ SOAP Web Service එකකින්. අදාල Inputs ලබා දිලා , Search එක ක්ලික් කරාම , වෙබ් බ්රව්සර් එකේ Console Tab එකේ "
" කියල පෙන්වනවා. හදා ගන්න උත්සහා කරන්න පුලුවන් හැම විධියක්ම බැලුව , ඒත් මුකුත් සෙට් වුනේ නැ. අන්තිමට Chrome එකට මේ Extension එක දාල තමයි Test කරේ.Failed to load http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?WSDL: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
ඒත් මට ඕන Extension භාවිතා නොකර මේක හදා ගන්නේ කොහමද කියල දැන ගන්නයි. උදව් කරන්න පුලුවන් නම් ලොකු දේයක්.
මේ පහල විධියට තමයි , Request එක යවන්නේ.
Code:
<script type="text/javascript">
$(document).ready(function () {
$('#ghsubmitbtn').on('click', function (e) {
var country = $('#country').val();
var year = $('#year').val();
var month = $('#month').val();
//console.log(departureDate);
var str = '<?xml version = "1.0" encoding = "UTF-8"?>' +
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.holidaywebservice.com/HolidayService_v2/">' +
'<SOAP-ENV:Body>' +
'<ns1:GetHolidaysForMonth>' +
'<ns1:countryCode>' + country + '</ns1:countryCode>' +
'<ns1:year>' + year + ' </ns1:year>' +
'<ns1:month>' + month + '</ns1:month>' +
'</ns1:GetHolidaysForMonth>' +
'</SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>';
//console.log(departureDate);
$.ajax({
url: 'http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?WSDL',
method: 'POST',
contentType: "text/xml; charset=utf-8",
data: str,
dataType: "text",
crossDomain: true,
//headers: {"Authorization": 'Bearer ' + bat},
success: function (data) {
console.log(data);
/* var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "HoliRes.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName('Country')[0];
var y = x.childNodes[0];
var x2 = xmlDoc.getElementsByTagName('Descriptor')[0];
var y2 = x2.childNodes[0];
document.getElementById("demo1").innerHTML = y.nodeValue;
document.getElementById("demo2").innerHTML = y2.nodeValue;
} */
document.getElementById("demo1").innerHTML=data;
var xml = data,
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$CountryXML = $xml.find( "Country" )[0].childNodes[0].nodeValue;
$( "#Country" ).append( $CountryXML );
//document.getElementById("Country").innerHTML = $y.nodeValue;
//$HolidayCode = $xml.find( "HolidayCode" );
//$( "#HolidayCode" ).append( $HolidayCode.text() );
$HolidayCodeXML = $xml.find( "HolidayCode" )[0].childNodes[0].nodeValue;
$( "#HolidayCode" ).append( $HolidayCodeXML );
$DescriptorXML = $xml.find( "Descriptor" )[0].childNodes[0].nodeValue;
$( "#Descriptor" ).append( $DescriptorXML );
$BankHolidayXML = $xml.find( "BankHoliday" )[0].childNodes[0].nodeValue;
$( "#BankHoliday" ).append( $BankHolidayXML );
$DateXML = $xml.find( "Date" )[0].childNodes[0].nodeValue;
$( "#Date" ).append( $DateXML );
var BookBtn = '<input type="submit" value="Book" name="book" class="btn btn-primary">';
for (var v = 0; v <= 999; v++) {
var row = $('<tr><td>' + $xml.find( "Country" )[v].childNodes[0].nodeValue + '</td><td>'
+ $xml.find( "HolidayCode" )[v].childNodes[0].nodeValue + '</td><td>'
+ $xml.find( "Descriptor" )[v].childNodes[0].nodeValue + '</td><td>'
+ $xml.find( "BankHoliday" )[v].childNodes[0].nodeValue + '</td><td>'
+ $xml.find( "Date" )[v].childNodes[0].nodeValue + '</td><td>'
+ BookBtn + '</td></tr>');
$('#tblData').append(row);
//$('#tblData').empty();
//$("#tblData").empty().$('#tblData').append(row);
}
//$('#tblData').load(row);
}
}); //Ajax
}); //Button
});
Last edited:
