Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
如何将withCredentials=true添加到Jquery.load()?_Jquery_Ajax_Xmlhttprequest - Fatal编程技术网

如何将withCredentials=true添加到Jquery.load()?

如何将withCredentials=true添加到Jquery.load()?,jquery,ajax,xmlhttprequest,Jquery,Ajax,Xmlhttprequest,我对Jquery还比较陌生 我正在使用Jquery.load()从另一个域获取一些内容,我需要使用会话cookie。有人知道如何将“withCredentials=true”添加到.load()函数吗 e、 g 谢谢。$。load()是一个非常精简的速记功能,不允许您传递设置 只需使用$.ajax()重新创建它的功能即可: 不过,考虑一下,您可能会使用$.ajaxSetup(),看看它是否能与load一起工作(还没有亲自尝试过)。在调用加载函数之前,请执行以下操作: $.ajaxSetup({

我对Jquery还比较陌生

我正在使用Jquery.load()从另一个域获取一些内容,我需要使用会话cookie。有人知道如何将“withCredentials=true”添加到.load()函数吗

e、 g

谢谢。

$。load()
是一个非常精简的速记功能,不允许您传递设置

只需使用
$.ajax()
重新创建它的功能即可:

不过,考虑一下,您可能会使用
$.ajaxSetup()
,看看它是否能与load一起工作(还没有亲自尝试过)。在调用加载函数之前,请执行以下操作:

$.ajaxSetup({
  xhrFields: {
     withCredentials: true
  }
});

请记住,这将影响来自jQuery的所有AJAX查询,这可能是您想要的,也可能不是您想要的。

谢谢!我刚刚用ajax创建了这个调用,它成功了。谢谢,没问题。好的第一个问题顺便说一句
$.ajax({
  url: 'https://example.com/somecontent.php',
  xhrFields: {
     withCredentials: true
  },
  success: function (data, status) {
    $('#displayPics').html(data.response).fadeIn();
  } 
});
$.ajaxSetup({
  xhrFields: {
     withCredentials: true
  }
});