Friday, 15 March 2013

How to send request for a web service from Javascript? -


I want to send the values ​​received from the HTML form to the web service via javascript. In the following code, while checking the connection status, I am able to receive alerts ('11 ') (readystate = 1); That is, the connection is established. But after some time I get a warning with a fallback in response

/ For some time, I have entered values ​​in XML, so country 1 and country 2 variables /

What should I change in this existing script?

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; SOAP JavaScript Client Test & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Festival Soap (Country 1, Country 2) {var xmlhttp = New XMLHttpRequest (); Warning ('1'); Xmlhttp.open ("post", "http://www.webservicex.net/Cu r rencyConvertor.asmx? Op = ConversionRate", is true); Warning ('2'); // Build SOAP request var sr = '& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; + '& Lt; Soapenv: envelope '+' xmlns: soap = "http://schemas.xmlsoap.org/soap/envelope/" '+' xmlns: web = "http://www.webserviceX.NET/" & gt; '+' & Lt; Soapenv: header / & gt; + '& Lt; Soaps: Body & gt; + '& Lt; Web: conversion rate & gt; ' + '& Lt; Web: fromCurrency & gt; USD & lt; / Web: FromCurrency & gt; + '& Lt; Web: ToCurrency & gt; EUR & lt; / Web: ToCurrency & gt; + '& Lt; / Web: ConversionRate & gt; + '& Lt; / Soapenv: body & gt; + '& Lt; / Soapenv: envelope & gt; '; Warning ('3'); Warning (SR); Xmlhttp.onreadystatechange = function () {if (xmlhttp.readyState == 4) {Warning (xmlhttp.responseText); If (xmlhttp.status == 200) {Warning ('Firebug used to view feedback'); }}} // Submit Post Request Warning ('4'); Xmlhttp.setRequestHeader ("SOAPAction", "http://www.webservicex.net/CurrencyConvertor.asmx"); Xmlhttp.setRequestHeader ('content-type', 'text / xml'); Warning ('5'); Xmlhttp.send (SR); Warning ('6'); // Submit Request // ... if (xmlhttp.readyState == 0) {Warning ('pass0'); } And if (xmlhttp.readyState == 1) {warning ('pass11'); } And if (xmlhttp.readyState == 2) {warning ('pass2'); } And if (xmlhttp.readyState == 3) {Warning ('Pass 3'); } And if (xmlhttp.readyState == 4) {Warning ('pass4'); }      return false; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "abc" onsubmit = "return soap (country 1, country 2)" & gt; & Lt; Label & gt; Country 1 & lt; Input type = "article" id = "country 1" & gt; & Lt; / Labels & gt; & Lt; Br> & Lt; Br> & Lt; Label & gt; Country 2 & lt; Input type = "article" id = "country 2" & gt; & Lt; / Labels & gt; & Lt; Br> & Lt; Br> & Lt; Input type = "submit" value = "submit" & gt; & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Div id = "mydiv" & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; Html & gt;  

thanks


No comments:

Post a Comment