简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM