我想從jquery ajax調用WCF服務,我只有undefined錯誤..幫我解決這個please.My服務工作正常,但我的問題是調用WCF從ajax.My代碼是在這裏從jquery ajax調用wcf服務undefined錯誤
$('#customerName').autocomplete({
source: function (request, response) {
var param ={email:$('#customerName').val()};
$.ajax({
url: "http://localhost:53925/Service1.svc/Getusermail/" + $('#customerName').valueOf(),
data:"{}",
dataType: "json",
type: "GET",
processData: true,
async:false,
contentType: "application/json; charset=utf-8",
error: function (XMLHttpRequest, textStatus, errorThrown)
{
var err = eval("(" + XMLHttpRequest.responseText + ")");
alert(err);
//console.log(err.Message);
},
success: function (data)
{
alert("correct code");
//response(data.d);
}
});
},
minLength: 1 //This is the Char length of inputTextBox
});
});
我已在WCF too..Thanks的web.config文件所需congiuration在Advance.And我的服務代碼是在這裏
public List<string> Getusermail(string email)
{
List<string> emailid = new List<string>();
string query = string.Format("SELECT email FROM nciuser WHERE email LIKE '%{0}%'", email);
//Note: you can configure Connection string in web.config also.
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=mbci;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
emailid.Add(reader.GetString(0));
}
}
}
return emailid;
}
及接口的上方方法是
[OperationContract(Name = "Getusermail")]
[WebGet(UriTemplate = "Getusermail/{email}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
List<string> Getusermail(string email);
請彰顯你在哪裏得到一個error..for更好的答案 – User125 2015-02-11 06:07:56
此行就只調用錯誤函數代碼但不是成功函數......即使我的服務工作正常 – 2015-02-11 06:17:03
如何定義「Getusermail」方法? – 2015-02-11 06:24:06