Search code examples
jqueryhttphandler

JQuery POST to Handler Data Params


Onlu just started picking up JQuery and came across a problem. Im trying to post to a Generic Handler and pass it Data Params.

The function looks like this:-

 function callSwapClaimHandler() {
        $.ajax({
            type: 'POST',
            url: "/handlers/investor-tickets/claimswapvalidator.ashx",
            data: { investorId : '1', investorTicketId : '2', originalClaimId : '3', newClaimId : '4' },
            contentType: "text/html charset=uft-8",
            success:
                function (data) {
                $("[id$='divMessageData']").html(data);
            }

        });

When i debug the function being called, it posts to the handler, and i can step through my code.

The problem is that Request form keys are empty, i have none of the above parameters.

Am i looking in the wrong place?


Solution

  • You are telling $.ajax to send the request data as "text/html" by using the contentType option.

    You likely meant to set the dataType which refers to the response.

    Simply removing the contentType property should remedy problem.

    From $.ajax Docs

    contentType (default: 'application/x-www-form-urlencoded; charset=UTF-8')
    When sending data to the server, use this content type.

    dataType (default: Intelligent Guess (xml, json, script, or html))
    Type: String The type of data that you're expecting back from the server.