Reputation: 13
How can I pass a local storage variable into the AJAX url: My problem is the variable "url" won't pass into the url section where I put + url +
Any help would be greatly appreciated. Thanks John
<script id="source" language="javascript" type="text/javascript">
$(function ()
{
$.ajax({
var url = localStorage.getItem('iphoneusername');
url: 'http://' + url + '.com/iphone/adddisplayapi.php',
data: "",
dataType: 'json',
success: function(data)
{
var id = data[0];
var name = data[1];
var pic1 = data[2];
document.write(name);
document.write("<br/>");
document.write(id);
document.write("<br/>");
}
});
});
</script>
Upvotes: 1
Views: 2045
Reputation: 100195
Try:
$(function () {
var urlParam = localStorage.getItem('iphoneusername');
$.ajax({
url: 'http://' + urlParam + '.com/iphone/adddisplayapi.php',
data: "",
dataType: 'json',
success: function(data) {
....rest of your code
Hope it helps
Upvotes: 1