Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery ajax请求数据未发送_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript jQuery ajax请求数据未发送

Javascript jQuery ajax请求数据未发送,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试一些关于ajax发送的想法,但是我找不到为什么这段代码不能向jsp发送任何参数并thorw nullpointerException 我在这里修复了我的代码,谢谢回复 var dfd = { resolve : function (res) { $("#Div123").html(res); } }; function getAjaxResponse(page, responseType, dataVar, dataV

我正在尝试一些关于ajax发送的想法,但是我找不到为什么这段代码不能向jsp发送任何参数并thorw nullpointerException

我在这里修复了我的代码,谢谢回复

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

数据更改为:

data: { dataVar : dataVal }
以及您的
数据类型

dataType: isJSON ? "JSON" : "text
它们都不接受函数


数据
接受普通对象或字符串,而
数据类型
只接受字符串

数据类型和数据选项不接受函数您必须调用函数并使用返回值:使用函数(){}(),而不是可能重复的感谢Amit Joki,您解决了我的问题。