Vincent Ducroquet
Vincent Ducroquet

Reputation: 924

Numbers after url parameters in API ASP.NET and Jquery

I created a Rest API and I call it from jquery like this :

$scope.apiCall = function (_type) {    
    $.ajax({
        type: "GET",
        url: "./handler/api.ashx/" + _type,
        cache: false,
        dataType: "json",
        contentType: "application/json; charset=UTF-8",
        success: function (datas, textStatus, xhr) {
            //my code
        },
        error: function (xhr, textStatus, errorThrown) {
            console.log(errorThrown);
        }
    });
}

And my API is like this :

if (Request.RequestType == "GET")
    {
            string RawUrl = Request.RawUrl;
            string splitter = "api.ashx/";
            string SubRawUrl = RawUrl.Substring(RawUrl.IndexOf(splitter) + splitter.Length);               
            string[] Parameters = SubRawUrl.Split('/');

            if (Parameters.Length == 1 && Parameters[0] != "") 
            {
                //My Code
                Response.Write(resp.ToJSON());
                Response.ContentType = "application/json";
            }
    }

But in my API, the Request.RawUrl returns this :

/handler/api.ashx/Contact?_=1493885783112

Where "/Contact" is my "_type" parameter in $scope.apiCall function.

I checked, in debug mode, the result of "_type", it returned "Contact", so why I have " =1493885783112" in my URL?

Upvotes: 1

Views: 57

Answers (1)

Eddi
Eddi

Reputation: 821

It's added because you set cache: false in your $.ajax()-call.

Have a look at the documentation. It adds the current timestamp ( in your case 1493885783112) and prevents browsers from caching the request since each request will be unique .

Upvotes: 1

Related Questions