- Screen name: drwat21
drwat21's Profile
31 Posts
32 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- Hi there!I'm using Ajax to get some data from an API. What I need to do is to use store the data into Local Storage when I call get the call back. Next time I'll update the page, I want to get the data from the Local Storage instead of geting the data from the API all the time. I do also have a timer that gives new data from the API after 1 hour. Actually, everything works fine, but my question how I can reuse (and not duplicate) the data in smart way. If you looking into the two functions 'getFromLS' and 'getFromAPI', I have not been able to figure out how to make this accessible outside one function into the other so to say..Thanks alot!jQuery(navHooker).append(myItem);console.log('fetch from Local Storge..' + myItem);'use strict';// --- Parameters --- //var navHooker = jQuery('#myNavigation > ul');// --- Check if we will use Local Storage or Live data --- //if (localStorage.getItem('myLsItem') === null) {getFromAPI();}else {var minutes = 1000 * 60;var hours = minutes * 60;var now = new Date().getTime().toString();var data = JSON.parse(localStorage.getItem('myLsItem'));if( now > (data['myTime'] + (1 * hours))){getFromAPI();}else {getFromLS(data);}}// Get data from Local Storagefunction getFromLS(){var myItem = data.items[0].volumeInfo.title;jQuery(navHooker).append(myItem);console.log('fetch from Local Storge..' + myItem);}// Get data from APIfunction getFromAPI(){jQuery.ajax({url: url,dataType: 'jsonp',success : function(data) {var myItem = data.items[0].volumeInfo.title;jQuery(navHooker).append(myItem);// var time now, append it to the end of the data object and stringify so it can be stored in Local Storagevar appTime = new Date().getTime();data.myTime = appTime;var jsonStore = JSON.stringify(data);localStorage.setItem('myLsItem',jsonStore);console.log('fetch from API..' + myItem );}});}and if you wanna try this, I used this example HTML<div id="myNavigation"><ul><li>Link 1</li><li>Link 2</li><li>Link 3</li></ul></div>
- Hi all, I got an success call back from an API in this way, everthing's fine so far.$.ajax({crossOrigin: true,url: url,success: function(data) {console.log(data.result);}});The API dont support JSONP, but i using http://www.ajax-cross-origin.com/ and store the proxy at google. Fine, but I can only get data back using data.resultIf I use Postman, to me it looks that I should use for example
data.result.ResponseData.Metros[0].DisplayTime to be able to get "Nu" as the image shows.How should I type the nodes?If i type for example data.result[0] I got a "{" back - but somehow I cannot select anything after "result", I want to select for example
data.result.ResponseData.Metros[0].GroupOfLine or something in this levelThanks!- Hi I wanted to create a link that is dynmaic in my site. The name could be 'Go Back', but it should not use go back history, I want the link to get up one level strict according to the nuber of slashes in the URL, e.g. in the structure of sites and pages I got,For example:If the I click such link on this page: https://forum.jquery.com/using-jquery/newtopic(I should be redirected to.. )Or.. If I'm at this level..Can we do such stuff with jQuery?And the same if I should go up 2 levels?Thanks!
- Hi!I try to get some data from one of those APIs out there..
What I can see in the documentation, this should be written something like the code below.
I got the data back in Postman, using the URL (with my own api Key), but in google chrome I just 'error ' got Unexpected token : and {"StatusCode":0," - btw, not sure what I should place in the headers..?Any one that could guide me here?Thanks in advance!- $(function(){
- $.ajax({
- async: true,
- dataType: 'json',
- crossDomain: true,
- url: "https://api.sl.se/api2/realtimedeparturesV4.json?key=xxxxx&siteid=9192&timewindow=60?callback=?",
- method: "GET",
- headers: {
- "Accept": "application/jsonp;odata=verbose",
- },
- })
- .done(successFunction)
- .fail(failFunction)
- function successFunction(data){
- console.log('ok..')
- }
- function failFunction(request, textStatus, errorThrown) {
- console.log('not ok.. ');
- }
- });
- Hi!
I have some JSON to deal with.
The given structure i have is like this.
..."days": [{"date": "2017-01-01","weekday": "Sunday","workfree day": "Yes",},
...
What I try to do is to use jQuery and Ajax to get an output of some of the values onto a web page.It works fine with for example:
var test1 = data.dagar[dayNr].date; (works fine)But..
One of the nodes have a blankspace: workfree day" - I haven't figured out how to solve that in my output..
var test2 = data.dagar[dayNr].workfree day; (don't work)
Any ideas?/ Thanks in advance- Hi all!I try to do some ajax call and have in my example three entries with some text content. What I try to do is to randomize one of the three items I get back. It works sometimes, and sometimes now when I do a page refresh. Btw in real cases it could be more than three items.What have I missed here?Thanks in advance!
- function successFunction(data) {
- var numberOfItems = data.d.results.length;
- for (var i = 0; i < data.d.results.length; i++) {
- var randItem = Math.floor(Math.random() * numberOfItems) + 1;
- var randText = data.d.results[(randItem)].QuoteText;
- $('.quoteText').html(randText);
- }
- }
- 14-May-2016 01:53 PM
- Forum: Getting Started
Hi guys!I'm looking for a way to just use one row for variables.. This stuff works, but I guess I should write this more effective?var H1 = moment.unix(data.hourly.data[0].time).format("HH"); var H2 = moment.unix(data.hourly.data[1].time).format("HH"); var H3 = moment.unix(data.hourly.data[2].time).format("HH"); var H4 = moment.unix(data.hourly.data[3].time).format("HH"); var H5 = moment.unix(data.hourly.data[4].time).format("HH")
what I want is to learn a way to incredemental count numbers..
x should start from 1 and can be up to some high number..
y always starts from 0 and its coming by jSON so this should be repeating like the above.. from 0 to 24. I need a stop after 24, date data sources have 48, but I want to stop after 24.var H(x) = moment.unix(data.hourly.data[y].time).format("HH");
would be great to see a reply!
Thanks
- Hi!I have a question about JSON in general, using jQuery with ajax.. What I try to do is to do is to display value based on URL from google api with geo codes.The thing is that the result in JSON will not always have exactly the same number of nodes.. Let's say I want node number 3, it's fine as long as there exist such node and a vaule in the node.https://maps.googleapis.com/maps/api/geocode/json?latlng=61.766008,61.197510 (have only two nodes, results[0].address_components[2].long_name and results[0].address_components[1].long_name )https://maps.googleapis.com/maps/api/geocode/json?latlng=41.766008,61.197510 - but the next one have more.I have tried with hasData or != but it seems that this is only for the values, but how can I check if there's 2 or more nodes in JSON?Thanks!
- 01-Sep-2014 05:44 AM
- Forum: Using jQuery
Hello!My questions if about the best way to write the following stuff most optimal with so few lines as posible? I provide an shorten example, in my case it should be much longer (A-Z). I hope you see what I trying to do.Thanks!- var Alfa = data.daily.[1].ico; // posible values A-Z
- var Beta = data.daily.[2].ico; // posible values A-Z
- var Gamma = data.daily.[3].ico; // posible values A-Z
-
- if (Alfa == 'A') {
- $('.testAlfa').attr('data-icon', 'A');
- }
- else if (Alfa == 'B') {
- $('.testAlfa').attr('data-icon', 'B');
- }
- else if (Alfa == 'C) {
- $('.testAlfa').attr('data-icon', 'C');
- }
- else{}
-
- if (Beta == 'A') {
- $('.testBeta').attr('data-icon', 'A');
- }
- else if (Beta == 'B') {
- $('.testBeta').attr('data-icon', 'B');
- }
- else if (Beta == 'C') {
- $('.testBeta').attr('data-icon', 'C');
- }
- else{}
-
- if (Gamma == 'A') {
- $('.testGamma').attr('data-icon', 'A');
- }
- else if (Gamma == 'B') {
- $('.testGamma').attr('data-icon', 'B');
- }
- else if (Gamma == 'C') {
- $('.testGamma').attr('data-icon', 'B');
- }
- else{}
-
-
- <span class="testAlfa" data-icon=""></span>
- <span class="testBeta" data-icon=""></span>
- <span class="testGamma" data-icon=""></span>
Hi! I have build a weather app with jQuery, and everthing works nice. The url is https://api.forecast.io/forecast/ with a couple of parameters after that. I have created a bunch of variables to store the data. Finally in the end I do like this:
-
var forecastData = function () {
$.getJSON(url, callback);
};
$(document).ready(function() {
forecastData();});
My question now if there's some easy way to handle errors, like if not null (if a param like longitude is missing), success/error - but to keep what I have coded so far? Have tried a bunch of thing but it wont work.
Thanks!
- 09-Jun-2014 03:34 PM
- Forum: Using jQuery Plugins
Hello!
I'm using rest to get som images from a data source. The REST works just fine. I using a jQuery Image slider library as well that also works just fine. However to combine this two seems a bit tricky becase if there seems to be some issue with the sequense the stuff loads.
I tried to change order and to use doc ready on the rest but it's not perfect.. The issue is that the images dont show up on the page until I hit F5 and reload the page.. but just sometimes, lets say it works 6 times of 10 when accessing the page for the first time :) If I press F5 it works often but sometimes not..
Any ideas on this?
<script type="text/javascript">
jQuery(window).load(function(){
$('#banner-slide').bjqs({
animtype : 'slide', //fade
height : 320,
width : 340
});
});
$.ajax({
url: "MyURLGoesHere..",
type: "GET",
headers: {"Accept": "application/json;odata=verbose"},
cache:false,
success: function(data){
var items = [];
items.push("<div id='banner-slide'>");
items.push("<ul class='bjqs'>")
$(data.d.results).each(function(){
items.push('<li>' + this.Title + '</li>');
});
items.push("</ul>");
items.push("</div>");
$("#output").html(items.join(''));
}
});
</script>
<div id="output"></div><script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="bjqs-1.3.min.js"></script>Hello!
I Think I've Close to a solution but I need help with the final touch of my code.. The thing is that I need to set a cookie on a navigation that is data driven.. the reason is that I want to set a select class because the page reloads after a click. The markup is given and I cannot change that.
<div class="test" id="1">Link 1</div>
<div class="test" id="2">Link 2</div>The following jQuery set a 'clicked' class on a div I click (that's great), but if I click on a let's say the next div (navigation item) I need to remove the previous clicked class.
Any Idea?
$('.test').on('click', function() {
$(this).addClass('clicked');
var clicked = $('.test.clicked').map(function() {
return '#' + this.id;
}).get().join(',');
$.cookie('MyCookie', clicked);
});var MyCookie = $.cookie('MyCookie');
$(MyCookie).addClass('clicked');Hello!
I have an Array of items, comming from a data source. What I want to do is to change the background color of the outher div when the user clicks on it. I have and id that can be a number from 1 up to let's say 100. I cannot do this with CSS because of the page will be refreshed after a click so I would like to set a cookie for this. However I cannot figure out how to do this.
I use thie jquery.cookies.js
<div class="xxx" id="{@ID}">
<a class="yyy" href="example.aspx?Title=@Title">
<div class="zzz">My dynamic data comes here ..</div>
</a>
</div>I have tried with something like this.. but I know is not right. Any thoughts?
$('.test').on('click',function(){
//var x = (this.id);
//alert(x);
$(this.id).css("background-color","red");
$.cookie('MyCookie', 'RED');
});
var MyCookie = $.cookie('MyCookie');
if (MyCookie == 'RED') {
$(x).css("background-color","red");
};Hello!
I need to extract the an image filename with out it's file extension.
Let's say I got this:
http://site/page/myimagename.jpgand what I want is to get is this result back:
myimagename
in other Words Everything after the last slash, but cut of 4 characters from right
Would be great if someone understands how to do this?
cheers
- Hey!
I have some dynamic generated divs, sometimes there's an image into one of the subdivs and sometimes not. What I need to do is to hide/remove the MyText class (remove the text) if there is an image in it's sibling class called MyImage... So if there's an image I want to hide the text belonging (parent) to this div the image lives into. Hope I explained this in a readable way
here's the dynamic generated HTML:
<div class="Content">
<div class="MyImage"><img src="someImage.jpg"/></div>
<div class="MyText">xxx</div>
</div>
<div class="Content">
<div class="MyImage"></div>
<div class="MyText">zzz</div>
</div>
<div class="Content">
<div class="MyImage"><img src="someImage.jpg"/></div>
<div class="MyText">yyy</div>
</div>
Anyone got an idea how to to this?
Thanks!- Hi all, I use the jquery.cookie plugin and I'm trying to remove rows when I click at a link.
The thing is, the content is database generated, so if it's 10 items in the database the NewsRows div renders 10 times. I can use the ID number to remove the rows, it works great, but what I need to do is to set every row I have removed from the click into a cookie. However I can set only one cookie per click, if I click at row number 99 (ID) this will be set in a cookie and if I reload the page the row 99 is gone. But.. If I now click att lets say row 56 - this new ID will be set in the cookie and the 99 have gone. In other word, how can I just add the new click ID number into the existing cookie?This would be really great if some one could help me out here! Thanks in advance.-- The markup --
<div class="NewsRow">
<a href="#{@ID}" id="{@ID}" name="{@ID}">Hide</a>
<div class="NewsContentContainer">
<div class="NewsTitle {@ID}">
<a href="#">Content..</span>
</div>
</div>
</div>-- The jQuery --jQuery(document).ready(function(){var cookieName = 'Item-';
var Options = {expires: 7, path: '/'};$(".container a").click(function(e){
var LinkID = $(this).attr('id');
$("." + LinkID).remove();
$.cookie(cookieName, LinkID, Options);});
$("." + $.cookie(cookieName)).remove();
});- Hi all, I have an input button with an img source and I have named the class to MyBtn. What I trying to do is to prevent more that one click at a button, and this is a dynamic page so it could be more than one button (like a gridview). It works but I would like to add a cookie as well, I using the jquery.cookie plugin. My idea is to replace the button image with another image once it have been clicked.
Would be great if someone have an idea about how to deal with a cookie here.$(".MyBtn").click(function(event){
event.preventDefault();
$.cookie('MyCookie', 'Clicked');
var ClickFunction = $.cookie('MyCookie');
if (ClickFunction == 'Clicked') {
$(this).replaceWith("<img src='/Clicked.png' />");
};
});- Hi, anyone know how to figure out how to replace an :-) in text? I would like to replace :-) with an smily icon.
I can replace :- but it seems like the ) is needs a special care in the pattern$('.SomeDiv').html(function(i,html) {
return html.replace(/:-/g, '<img src="/MyFolder/icon_smile.gif" />');
});Thanks!- Hello there!I would like to get some help with a script a just wrote. What I want to do is to preset a number of days (like 10 days maybe) and if today's date is equal to one of the dates an alert (or some function should trigger). I have manage this by the script below, but I wonder if I can write this more effective, and most important if I can extract the year, for example I want an alert every 01 Jan, every year (not just 2012). It would be great if someone have some ideas here!Thanks!$(document).ready(function() {var today = new Date().toDateString();var A = new Date("01 Jan 2012").toDateString();var B = new Date("14 Feb 2012").toDateString();var C = new Date("25 Dec 2012").toDateString();if (today == A) {alert("Happy New Year");}else if (today == B) {alert("Valentine");}else if (today == C) {alert("Happy Christmas");}else {}});
- Hi there!
I want to check if a DIV contains a specific text, if it does, i want to add a new class to the parent of this class.I thinking of something like this:if ($('.SomeClass:contains("SomeText")').length > 0)
{
$(this).parent().addClass("NewClass");
}This is in a table so I need to add the new class specific to this TDs parent, not every TDs.Thanks!- Hi there!I want to capture a dynamic text inside a meta tag, I can do that in this wayvar MyVar = $('meta[name=server]').attr("content");
alert(MyVar);But if this dynamic text is let say 'Page number one'
I need to use if (i guess) and else.
If the content contains 'Page number one' i would like to 'do something' but if the content is empty (it could be) I want to do 'something else'Any Ideas?- Hi there!I have an script for a vertical (leftside menu) that (almost) works in the way I would. The think is that when I have clicked on a link, i want to have this section open in the menu, the parent header link with all its children links visibly. I have managed to do that with $selPos = $('.menu > ul.Node > li.Node > ul.Node > li.selected');
if($selPos.length){
but.. the exp/collapse will not work in conjunction to this, what I want is when I have clicked on a link I want to see it's parent header link with an minus icon (collapse) instead of the plus (expand). The links comes dynamic and it's an control in .net som I can not rewrite the markup, I had to use Prepend (I think I had) to inject the icons in a span before an actuall header link.If anyone have some idéas here, it would be great!Thanks//updated//I have updated my script a bit more but my issue remains, please see http://jsfiddle.net/kuUXN/28/$(document).ready(function() {// No expand by default
$(".menu > ul.rootUL > li.Node > ul.Node").hide();// Prepend exp/col icon if there is sublinks
$HasSubMenu = $('.menu > ul.rootUL > li.Node > ul.Node');
if($HasSubMenu.length){
$HasSubMenu.parent().prepend('<span id="PrependedIconExpand"></span>');
}// Toggle functions
$(".menu > ul.rootUL > li.Node > span").toggle(
function () {
$("ul.Node", $(this).parent()).show("fast");
$($(this)).css("background","url('/images/col.png') no-repeat 0px 6px");
},
function () {
$("ul.Node", $(this).parent()).hide("fast");
$($(this)).css("background","url('/images/exp.png') no-repeat 0px 6px");
}
);// Keep expanded after selected
$selPos = $('.menu > ul.Node > li.Node > ul.Node > li.selected');
if($selPos.length){
$selPos.parent().css({'display': 'block'});
}
});The markup:<div class="menu">
<ul class="rootUL">
<li class="Node">
<a class="TheLink" href="#">Link1</a>
</li>
<li class="Node">
<a class="TheLink" href="#">Link2</a>
<ul class="Node">
<li class="Node">
<a class="TheLink" href="#">Link2-SubLink1</a>
</li>
<li class="Node">
<a class="TheLink" href="#">Link2-SubLink2</a>
</li>
</ul>
</li>
<li class="Node">
<a class="TheLink" href="#">Link3</a>
</li>
</ul>
</div>And the CSS:#PrependedIconExpand{
float:left;
background-image:url('/images/exp.png');
background-repeat:no-repeat;
background-position:0px 6px;
width:11px; height:11px;
padding-top:3px;padding-bottom:3px
}- Hi there!I got a dropdown in a form that I would like to set with a value that I get from a servercontrol. This value is dynamic and I can fetch this from it's CSS class. It's working just fine, but if the dropdown has 20 or more items (options) it's not working in IE9 and below. It seems like the dropdown in IE turn into another kind of hybrid mode when it's 20 or more, but it's working just fine if 20 or more in other browsers.
This script will do it if the items are below 20:
var Simple = $('.CurrentPageID').html();
$("select[title='PagesID']").val(Simple);If I use input instead of select, the dropdown will display what I want, but I cannot save that value, because I have to physically select the value that displays in the dropdown, it seems just to be selected but it is not..var Complex = $('.CurrentPageID').html();
$("input[title='PagesID']").val(Complex);Any ideas out there?- Hi there!
Anyone know how to modify the DOM with jQuery in order to correct an (dynamic) HTML structure. I have a markup like this:
Thinking about a replacewith or append or a combination??<ul class="MyClass">
Test1 <br />
Test2
</ul>
But I need to get all texts in the UL be surronded by LIs, and to delete the br.
<ul class="MyClass">
<li>Test1<li>
<li>Test2</li>
</ul>In real life this could be a like two text elements like in this example, but it´s dynamic so it could be like 3 or 15 or whatever sometimes.Thanks!- Hi there, my question if it´s posibly to dynamical open (without hardcode URL) the same page (current page) in a dialog? I need to have a link on every every page in a site (the link lives into a template) and I need to open this page again in a dialog box with the same content. Anyone know the trick?
- «Prev
- Next »
Moderate user : drwat21
© 2013 jQuery Foundation
Sponsored by
and others.
-