【问题标题】:Sending localStorage variables through the jQuery Ajax function without it being in the url通过 jQuery Ajax 函数发送 localStorage 变量而不在 url 中
【发布时间】:2012-10-07 12:25:07
【问题描述】:

早安,

我想知道是否有一种方法可以通过 Ajax 函数发送 localStorage 变量,而不是在 url 中。例如:

$.ajax({
    type: "POST",
    url: "../pages/profile.php",
    data: localStorage.email,
    dataType: 'json'
    success: function(result)
    {     
        //document.location.replace('../pages/main.php');
    },
    error: function()
    {
        alert('An Error has occured, please try again.');
    }
});

在这种情况下,php 的返回类型将是 JSON,根据需要。

提前致谢

【问题讨论】:

    标签: php jquery html ajax local-storage


    【解决方案1】:

    改变

    data: localStorage.email,
    

    data: {email: localStorage.getItem('email')}
    

    这样data 是正确的 JSON 格式,并使用(我相信)正确的方法从 localStorage 检索项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-30
      • 2015-08-17
      • 2016-12-04
      • 1970-01-01
      • 2017-03-14
      • 2014-02-07
      • 2013-06-21
      • 2018-01-06
      相关资源
      最近更新 更多