3
我在VS2010
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
// TODO: Add your service operations here
}
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
以下調用開發了一個簡單的WCF服務工作
protected void Button1_Click(object sender, EventArgs e)
{
ServiceReference1.Service1Client p = new ServiceReference1.Service1Client();
Label1.Text= p.GetData(5);
}
,但是當我試圖打電話它從jquery它不能正常工作
$(".test").live("click", function() {
$.ajax({
type: "post",
url: "http://localhost/Service1.svc/GetData",
data: {value:'1'},
contentType: "application/json; charset=utf-8",
timeout: 10000,
processData: true,
dataType: "json",
success: function(d) {
alert(d);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError.toString());
}
});
有人可以幫助我因爲它給了我不眠之夜。 在此先感謝。