如果你能夠在你的解決方案中使用jquery,並且你想從客戶端完全使用jquery。你可以這樣做:
<script type="text/javascript">
function CallService() {
$.ajax({
type: "POST", //You can use POST or GET (GET works a little different)
url: "YourWebService.asmx/GetSomeData", //This assumes a relative path, you can use any url.
data: "{}",
contentType: "application/json; charset=utf-8", // you must define the content type (though I am not sure what other options are of any value here...)
dataType: "json", //you can do json or XML serialization, do json, it is easier in the long run.
success: Success, //this is a reference to the "function Success" to be invoke by the the service return.
error: Error //ditto for the function Error...
});
}
function Success(data, status) {
//do what you want with the data...
}
function Error(request, status, error) {
//something in the soup ain't right...
}
</script>
這實際上和使用ajax和jQuery調用Web服務一樣容易。
JQuery是一個可用選項嗎? – 2011-04-28 20:24:10