Why does $.ajaxSetup not work with $.post

风格不统一 提交于 2021-01-28 21:37:09

问题


Why does this code post the sessionID parameter

    $.post("ajax/p_getOnePosition.jsp", {
        positionNo: positionNo,
        sessionID: v_sessionID,
    }, function(response2) {

But not this code

    $.ajaxSetup({
        sessionID: v_sessionID,
    });
    
    $.post("ajax/p_getOnePosition.jsp", {
        positionNo: positionNo,
    }, function(response2) {

回答1:


Use beforeSend instead as follows. Code inspired from here

$.ajaxSetup({
     beforeSend: function (jqXHR, settings) {
        settings.data += "&sessionID="+v_sessionID;
  }
});

$.post("ajax/p_getOnePosition.jsp", {
    positionNo: positionNo,
}, function(response2) {


来源:https://stackoverflow.com/questions/65617103/why-does-ajaxsetup-not-work-with-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!