2016-11-19 34 views
-1

從瀏覽器的Localstorage獲取數據,然後將其存儲在Varibale中並將其分配給Ajax調用URL。 下面是我遵循的步驟:將LocalStorage值分配給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內部服務器錯誤。

+0

的問題解釋還不很清楚,因此很難理解 – charlietfl

+0

好它是什麼需要被添加? –

+0

一個正確和簡潔的問題陳述 – charlietfl

回答

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>

+0

感謝提示我做了console.log('https://apex.oracle.com/pls/apex/tabularmagic/employees/'+id+'/'+mid); 它返回https://apex.oracle.com/pls/apex/tabularmagic/employees/7698/7839 似乎有價值 –

+0

謝謝,因爲我找到出路做同樣的 –