我一直试图让这个ajax调用工作几个小时,并且无法解决任何可能的问题,因为根据jQuery Ajax Call,所有内容似乎都已正确编码。据我所知,代码甚至没有被执行。但是,当我手动运行API调用时,我得到以下JSON结果:
<UnitsOfMeasure.UnitsOfMeasureDataWithMessage xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Corporate.Web.API.DAL">
<Message/>
<Success>true</Success>
<UnitOfMeasureBaseUnitItem i:nil="true"/>
<UnitOfMeasureBaseUnitList i:nil="true"/>
<UnitOfMeasureRelatedUnitItem i:nil="true"/>
<UnitOfMeasureRelatedUnitList i:nil="true"/>
<UnitOfMeasureSetItem i:nil="true"/>
<UnitOfMeasureSetList i:nil="true"/>
<UnitOfMeasureTypeItem i:nil="true"/>
<UnitOfMeasureTypeList i:nil="true"/>
<UsedForID>d64d99f9-acfa-44cd-a199-4557b7b20912</UsedForID>
</UnitsOfMeasure.UnitsOfMeasureDataWithMessage>
我的API代码如下:
[Route("api/admin/UnitsOfMeasure/UnitOfMeasureDefaultUsedForGetID")]
[HttpGet]
[ResponseType(typeof(UnitsOfMeasure.UnitsOfMeasureDataWithMessage))]
public IHttpActionResult UnitOfMeasureDefaultUsedForGetID(string UnitOfMeasureDefaultUsedForName)
{
UnitsOfMeasure _oUnitsOfMeasure = new UnitsOfMeasure();
return Ok(_oUnitsOfMeasure.UnitsOfMeasureSet_GetUsedForID(UnitOfMeasureDefaultUsedForName));
}
我的DAL应该返回一个布尔标志和一个Guid。
我的Ajax调用如下:
$.ajax({
type: "GET",
url: g_WebServiceUnitOfMeasureDefaultUsedForGetIDURL,
data: {"UnitOfMeasureDefaultUsedForName": "Purchase"},
datatype: "json",
success: function(jsonResult){
DefaultUnitUsedForID = jsonResult;
},
failure: function (xhr, textStatus, errorThrown) {
console.log(xhr);
console.log("---------------------------------------------------------------------------");
console.log(textStatus);
console.log("---------------------------------------------------------------------------");
console.log(errorThrown);
console.log("---------------------------------------------------------------------------");
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr);
console.log("---------------------------------------------------------------------------");
console.log(textStatus);
console.log("---------------------------------------------------------------------------");
console.log(errorThrown);
console.log("---------------------------------------------------------------------------");
}});
如上所述,从单步执行代码开始,它甚至不会输入成功或失败功能。我做错了什么?
答案 0 :(得分:0)
可能是愚蠢的,但是给它一个拍摄
$.get( g_WebServiceUnitOfMeasureDefaultUsedForGetIDURL,
{"UnitOfMeasureDefaultUsedForName": "Purchase"} )
.done(function( data ) {
DefaultUnitUsedForID = jsonResult;
alert( "Data Loaded: " + data );
});
答案 1 :(得分:0)