TimeGuard
TimeGuard

Reputation: 5

jQuery ajax request data not send

i am trying some idea on a ajax send,but i can't find why this code can't not send any parameter to jsp and thorw the nullpointerException.

I fix my code here,thanks for reponse.

var dfd = {
        resolve : function (res) {
             $("#Div123").html(res);
        }
    };

function getAjaxResponse(page, responseType, dataVar, dataVal, dfd) {
    var dataObject = $.parseJSON('{"'+ dataVar +'":"'+ dataVal +'"}');
    $.ajax(page, {
        type: 'POST',
        dataType: responseType,
        data: dataObject,
        success: function (responseData) {
            dfd.resolve(responseData);
        }
    });
}

$(document).ready(function(){   
    $("#submit").click(function(){
        getAjaxResponse("ajaxreponse.jsp", "text", "aa", "yes", dfd);
    }); 
});

Upvotes: 0

Views: 159

Answers (1)

Amit Joki
Amit Joki

Reputation: 59232

Change your data to:

data: { dataVar : dataVal }

and your dataType to

dataType: isJSON ? "JSON" : "text

They both don't accept functions.

data accepts plain object or string and dataType accepts only string

Upvotes: 1

Related Questions