這裏我給json格式輸入,但我沒有得到output.could任何人請解決這個問題。jQuery jsonp跨域請求到遠程ASP.NET web服務
我有一個關於JSONP一些疑問:
1)我有一個疑問序使用JSONP調用遠程Web服務,我們應該有JSON格式或查詢字符串格式發送數據。
2)在這裏,如果我們訪問url並給出輸入,那麼我們將以xml格式獲得o/p。所以我只想知道jsonp是否會爲輸出xml的webservices工作。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript">
function myQuerySuggestions() {
var searchText = document.getElementById('txtsearch').value;
searchText = "'" + searchText + "'";
var jasonData = "{" + 'Celsius:' + searchText + "}";
$.ajax({
url: "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit",
dataType: "jsonp",
crossDomain: true,
data:jasonData,
jsonpCallback: blah,
contentType: "application/json; charset=utf-8",
success: function (data, status) {
alert(status+" status");
},
error: function() { alert("error"); }
});
}
function blah(data) {
alert("called");
alert(data);
// var result = (typeof data.d) == 'string' ? eval('(' + data.d + ')') : data.d;
// $('#summary').html('<p>All new content. <em>You bet!</em></p>');
// $('#summary').html(result);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label for="txtsearch">
Enter country:
</label>
<input type="text" id="txtsearch" size="43" style="font-size: 12px; font-weight: bold;" />
<br />
<asp:Button ID="btn" runat="server" Text="Submit" OnClientClick="myQuerySuggestions();return false;" />
<div id="summary" runat="server"></div>
</div>
</form>
</body>
</html>
請告訴我,如果問題不明確.. –