将LocalStorage值分配给名为URL的Ajax

时间:2016-11-19 19:15:02

标签: javascript jquery arrays json ajax

从浏览器的Localstorage获取数据,然后将其存储在Varibale中并将其分配给Ajax调用URL。 以下是我遵循的步骤:

//when document is ready get those DATA from LocalStorage.
var mid = localStorage.getItem('mid');
var id = localStorage.getItem('id');
console.log(mid);//7839
console.log(id);//7698

//At the same time assign it to URL.
$.ajax({
    contentType : 'application/json; charset=utf-8',
    dataType : 'json',
        url:'https://apex.oracle.com/pls/apex/tabularmagic/employees/'+id+'/'+mid,
    method : 'GET',
    success:  function (data) {
    //my logic
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.log("some error from Customers" +errorThrown+"//"+textStatus);
    }
    });

如果您愿意,可以直接调用此URL: https://apex.oracle.com/pls/apex/tabularmagic/employees/7698/7839

(其中empno = id且MGR = mid)

问题是我无法将此变量值分配给此URL。 错误:500内部服务器错误。

1 个答案:

答案 0 :(得分:1)

因此,在不使用localStorage的情况下使用变量中的静态值可以正常工作。所以问题似乎是从localStorage获取数据。确保在进行连接时可以使用它们



//when document is ready get those DATA from LocalStorage.
var mid = '7839';
var id = '7698';
console.log(mid);//7839
console.log(id);//7698
console.log('https://apex.oracle.com/pls/apex/tabularmagic/employees/'+id+'/'+mid);

//At the same time assign it to URL.
$.ajax({
    contentType : 'application/json; charset=utf-8',
    dataType : 'json',
        url:'https://apex.oracle.com/pls/apex/tabularmagic/employees/'+id+'/'+mid,
    method : 'GET',
    success:  function (data) {
    console.log(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.log("some error from Customers" +errorThrown+"//"+textStatus);
    }
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;