0

I call http://wsf.cdyne.com/WeatherWS/Weather.asmx web service from JavaScript. And I pass data ZIP code as 10007(Hard coded). Want to get some output data. But when I run the code success message come as alert and then alert pop up says none. Seems there is no data returned. Can anyone edit the code to return proper output?

<html>
     <head>
        <title>Calling Web Service from jQuery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#btnCallWebService").click(function (event) {

                    $.ajax({
                        type: "POST",
                        url: "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: "10007",
                        success: processSuccess,
                        error: processError
                    });

                });
            });

            function processSuccess(data, status, req) { alert('success');
                if (status == "success")
                    $("#response").text($(req.responseXML).find("Result").text());
                    alert(req.responseXML);
            }

            function processError(data, status, req) {
            alert('err'+data.state);
                //alert(req.responseText + " " + status);
            } 

        </script>
    </head>
    <body>
        <h3>
            Calling Web Services with jQuery/AJAX
        </h3>
       <input id="btnCallWebService" value="Call web service" type="button" />
        <div id="response" ></div>
    </body>
    </html>
user3860579
  • 33
  • 1
  • 1
  • 4

2 Answers2

0

Try This

$.ajax({
      url: "URL",
      dataType: "json",
      data: {term: request.term},
      success: function(data) {
        alert(data);
        var dData = JSON.parse(data);
        alert(dData.Name); //get your stuff
      }
    });
cracker
  • 4,900
  • 3
  • 23
  • 41
0

Did you enabled CORS themessage i am getting when i tested in firebug is as below

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP. This can be fixed by moving the resource to the same domain or enabling CORS.

these links might help you

http://enable-cors.org/client.html

Firefox setting to enable cross domain ajax request

Community
  • 1
  • 1
Arvin
  • 954
  • 3
  • 14
  • 33