1

I am trying to do a Sample Currency Converter Mobile Application with the help of free webservice http://www.webservicex.net/CurrencyConvertor.asmx?WSDL I am using jQuery mobile and HTML5 for my Application.When trying to access the webservice I am getting this Error Error:receive is not called(receive is a JsonpCallback function which I defined) Here is my Jquery Code

    script type="text/javascript" charset="utf-8">
   function receive(result){
        console.log(result)
     }

 $( document ).on( "pagecreate", "#home", function( event ) {
     //alert( "This page was just enhanced by jQuery Mobile!" );
    $("#submit").bind("tap",function(){
        // alert("called");
        // var ConversionRate =$("#value").val();
        // console.log(ConversionRate)
         var FromCurrency = $("#fromcurrency option:selected").val();
         console.log(FromCurrency)
         var ToCurrency = $("#tocurrency option:selected").val();
         console.log(ToCurrency)



         $.ajax({
            crossDomain: true,
            type:"GET",
            contentType: "content/xml; charset=utf-8",
            async:false,
            url: "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate",
            data: {FromCurrency :FromCurrency,ToCurrency :ToCurrency},
            dataType: "jsonp", 
            jsonpCallback: "receive",
            success: function(result){
                console.log("Success")
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                console.log(XMLHttpRequest, textStatus, errorThrown)
                console.log(XMLHttpRequest.responseType)
            }
        });
    });
});


</script>

Here is my Response xml File

<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">61.155</double>

Screenprint of Error:

http://s28.postimg.org/f11gvkgyl/Error.jpg

I got a response xml with a Syntax Error which i can see it in firebug console.So it is not called by success handler,Any solutions for this problem.Thanks

user3431651
  • 91
  • 2
  • 2
  • 14
  • I don't know if this is part of your issue or not, but you can't have `async: false`, `crossDomain: true` and `dataType: "jsonp"`. JSONP has to be `async: true` because it's implemented via a script tag. Also, why are you using the `jsonpCallback` option rather than just letting jQuery do the work for you can call your success handler? – jfriend00 Mar 18 '14 at 06:08
  • I tried Without `jsonpCallback` Option but it shows `callback=undefined` in the Url.i am stucked here for 2days :( – user3431651 Mar 18 '14 at 06:17
  • changed `async:` to `true` but no changes. – user3431651 Mar 18 '14 at 06:23
  • Remove the `async: false` and `jsonpCallback: "receive"` options and then see if it calls the `success` handler. – jfriend00 Mar 18 '14 at 06:23
  • Does `http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate` specifically support the `callback=xxx` option of JSONP? – jfriend00 Mar 18 '14 at 06:25
  • Removed `async: false` and `jsonpCallback :"receive"` but now the Error Message Was `Error: jQuery111009069179260686013_1395124051383 was not called ` – user3431651 Mar 18 '14 at 06:31
  • That sounds like your server doesn't support JSONP. You can only do cross domain JSONP requests if the server specifically supports the JSONP method of doing that. – jfriend00 Mar 18 '14 at 06:32
  • Ya it supports because I am getting a Response in an Xml Format which I can see it in console with an error `SyntaxError: syntax error` – user3431651 Mar 18 '14 at 06:33
  • Since when did you say you were getting an error response? That sounds like your server is returning XML, not JSONP. JSONP is a specific format for the response. – jfriend00 Mar 18 '14 at 06:35
  • I say once again that your server is not returning JSONP. Either it doesn't support JSONP or you aren't specifying the request the right way to tell it to return the response in JSONP format. – jfriend00 Mar 18 '14 at 06:37
  • Sorry..This is my first mobile Application and I am using Jquery for the first time.I am confused in that. – user3431651 Mar 18 '14 at 06:38
  • Take a look here: http://stackoverflow.com/questions/923481/problem-with-calling-remote-asmx-using-jquery. It looks that service only returns XML, not JSONP so can't be used cross domain. – jfriend00 Mar 18 '14 at 06:43
  • Hi @jfriend00! Thanks for your responses and suggestions.I tried with `datatype:xml` and `datatype:json` but couldn't figure it out :-( – user3431651 Mar 18 '14 at 12:02

0 Answers0