HTTPGET fail when passing C# entity class to json-jquery
Here's my jquery:
$.ajax({
type: 'GET',
url: '/services/Service.asmx/FamilyHistory',
data: JSON.stringify({
userID: 10,
historyID: famid
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(val) {
var famHist = val.d;
alert(famHist.ID);
},
error: function() {
parent.$.jGrowl('<b>Failed</b>',
{
header: 'User Action:',
开发者_开发知识库 life: 3000
});
}
});
My Class:
public sealed class FamilyHistoryEntity
{
public string ID { get; set; }
public string RelativeName { get; set; }
}
My Web service:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public FamilyHistoryEntity FamilyHistory(int userID, string historyID)
{
return GetFamilyHistory(historyID, userID); // returns a FamilyHistoryEntity class
}
Problem is, i can't even make it do a breakpoint onto the webservice, it just throws the jquery ajax event of error.
Why are you using the stringify function? It would seem like it is looking to call a method with a string parameter rather than the two parameters you have for your method.
Maybe I am missing something?
EDIT: So you would change the data property to:
data: { userID: 10, historyID: famid },
Especially since you specify the contentType as json.
精彩评论