当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Getting no response from an ajax call

问题描述:

I have been trying to get this ajax call to work for several hours and have not been able to resolve any possible issues as everything appears to be coded properly according to jQuery Ajax Call. From what I can tell the code is not even being executed. However when I manually run the API call I get the following JSON result:

<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>

My API Code is as follows:

[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));

}

My DAL is supposed to return a Boolean flag and a Guid.

And my Ajax call is as follows:

$.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("---------------------------------------------------------------------------");

}});

As mentioned, from stepping through the code, it does not even enter the success or failure functions. What am I doing wrong?

网友答案:

May be it is foolish, But give it a shoot

$.get( g_WebServiceUnitOfMeasureDefaultUsedForGetIDURL,
{"UnitOfMeasureDefaultUsedForName": "Purchase"} )
.done(function( data ) {
DefaultUnitUsedForID = jsonResult;
alert( "Data Loaded: " + data );
});
网友答案:

john,

would you please read this articles that may be help to you

http://www.codeproject.com/Articles/617892/Using-CORS-in-ASP-NET-WebAPI-Without-Being-a-Rocke

分享给朋友:
您可能感兴趣的文章:
随机阅读: