我想使用下面的服务抛出 JQuery: http ://www.webservicex.net/globalweather.asmx/GetCitiesByCountry 但它只执行错误功能,我在下面尝试:
        function serviceCall() {
        var txtInput = $("#txtInput").val();
        var webMethod = 'http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry';
        var datap = {"CountryName":JSON.stringify("Italy")}; 
        $("#divResult").html('loading...');
        $.ajax({
            type: "POST",
            url: webMethod,
            data: datap,// { "CountryName" : JSON.stringify("Italy")},
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp", //for Firefox change this to "jsonp"
            success: function (response) {
                alert("reached success");
                $("#divResult").html(response.d);
            },
            error: function (e) {
                $("#divResult").html("Unavailable: " + txtInput);
            }
        });
    }
所以我收到不可用:意大利
以下是整页代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
        function serviceCall() {
        var txtInput = $("#txtInput").val();
        var webMethod = 'http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry';
        var datap = {"CountryName":JSON.stringify("Italy")}; 
        $("#divResult").html('loading...');
        $.ajax({
            type: "POST",
            url: webMethod,
            data: datap,// { "CountryName" : JSON.stringify("Italy")},
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp", //for Firefox change this to "jsonp"
            success: function (response) {
                alert("reached success");
                $("#divResult").html(response.d);
            },
            error: function (e) {
                $("#divResult").html("Unavailable: " + txtInput);
            }
        });
    }
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
    <input type="text" id="txtInput" value="Italy"/>
    <br />
     <div style="width: 100px; height: 30px; background-color: yellow;" onclick="serviceCall();">
    Click me</div>
<div id="divResult" runat="server">
</div>
</form>
</body>
</html>
有什么帮助解决这个问题吗?