如何使用ajax GET方法将参数从输入字段解析为URI

时间:2016-01-05 11:38:42

标签: jquery ajax get

我正在使用asmx webservice,它有一个方法,有两个参数
1,UserTicket
2,ZipCode。
我发送userTicket编码,但我希望用户提供邮政编码。我的服务只能使用ajax GET方法。

<script>
        function callwm() {
            var zipcode = $('#zip').val();
            $.ajax({
                type: "GET",
                url: "https://services.opisnet.com/RealtimePriceService/RealtimePriceServicePlus.asmx/GetZipCodeResults?UserTicket=0Hv9MEJRuKaun58MzNlhz0H30WlHxQCUB6ZfUa2dS7eVwA4x1QvSmR4Dml/lnfFm",
                data: "&ZipCode=" + encodeURIComponent($('#zip').val()),
                dataType: "xml",
                async: true,
                success: function (result) {
                    var xmlString = new XMLSerializer().serializeToString(result);
                    var lnt = "<Station_Name>".length;
                    var ind = xmlString.indexOf("<Station_Name>");
                    var lst = xmlString.indexOf("</Station_Name>");
                    var str = xmlString.substr(ind + lnt, lst - (ind + lnt));
                 $('#res').text('Station Name:  '+str);
 },
                failure: function (data) {
                    alert('failure');
                },
                error: function (xhr, status, error) {
                    alert(xhr.responseText);
                }
            })
}
</script>

HTML

<input id="Button1" type="button" value="Get list" onclick="callwm();" />

0 个答案:

没有答案