hi;如何在jquery html應用程序中使用wcf服務作爲遠程或本地?我已經準備好了一項wcf服務。我想通過jquery ajax方法在html文件中使用。任何錯誤都不會返回。如何在jquery html應用程序中使用wcf服務作爲遠程或本地?
WCF側VS 2010:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
HTML中的Aptana工作室:
代碼:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js"></script>
$(document).ready(function() {
$("#sayHelloButton").click(function(){
alert("fsf");
$.ajax({
type: "POST",
url: "Service1.svc/GetData",
data: "{'id': '" + 1 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
測試
點擊我首頁
<div>
</div>
<footer>
<p>© Copyright by yusufkaratoprak</p>
</footer>