Search Results

Search found 326 results on 14 pages for 'getjson'.

Page 6/14 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • JQuery DataTables link item

    - by rogcg
    I'm trying to link the items from a specific column, but each one will be linked for a different id from the json string. Unfortunately I can't find a way to do this using the API (I know there is a lot of ways to do that without using the API ), but I'm looking for a way to link a item from a column (each one with a link for a specific id). So here is my code, I use getJSON to get the JSON from the server, and I load the data from this JSON to the table like this: $.getJSON("/method/from/server/", function(data) { var total = 0; $("#table_body").empty(); var oTable = $('#mytable').dataTable( { "sPaginationType" : "full_numbers", "aaSorting": [[ 0, "asc" ]] }); oTable.fnClearTable(); $.each(data, function(i, item) { oTable.fnAddData( [ item.contact_name, item.contact_email ] ); }); }); What I want to do, is for each row, link the contact_name to its id, which is also in the JSON, and can be accessed inside this $.each loop by using item.contact_id. Is there a way to do this using DataTables API, if yes, could you explain me and provide a good resource that will help me with this? Thanks.

    Read the article

  • JSONP not firing on IPad

    - by Gemtag
    After trying everything possible I've come to the conclusion this is an issue with IPad Safari. This works in FF, IE, Chrome, and Safari on MacBook. Below is my dumbed-down code. I have 2 separate JSONP calls, This first one works in all browsers including IPad. This simply calls a function based on a blur event $('#gender').blur(function() { reTarget(); }); function reTarget() { $.getJSON("http://host.com/Jsonpgm?jsoncallback=?", function() { } ); } Below is where things break. On the same page as the above code is the following, which calls a function based on a submit button click. $(':submit').bind('click', function(event) { if (checkThis() == false) { return false; }; }); $('form').bind('submit', function(event) { if (checkThis() == false) { return false; }; }); function checkThis() { $.getJSON("http://host.com/Jsonpgm.aspx?jsoncallback=?", function() { } ); } This code will not fire. I've put alerts right before it and they fire. I look at the web logs and there is no entry for this json call. I would take any suggestions on this. At this point I fear it's a problem with firing jsonp from a submit event.

    Read the article

  • How To: Custom HTML / CSS Text Button for "Facebook like" & "Twitter Follow"

    - by 1Line
    So i have had a little hunt online about creating custom Facebook like buttons and custom twitter follow button but not really found a solution so thought i would ask here and see if anyone knows of a solution for this (currently i have coded some jQuery to get Facebook and Twitter counts using JSON which works but want some custom buttons as per below) I have the count working all ok, just need to tackle the like and follow buttons - it is done in jquery at the moment so would like to continue to use that if this has to be done via that. at the moment i use the API for each to get the count, if i can integrate into the current js i have to get the calls / functions i require would be good: // grab from facebook var facebook = $.getJSON('https://graph.facebook.com/'+f_page+'?callback=?', function(data) { fb_count = data['likes'].toString(); fb_count_gt = data['likes'].toString(); fb_count = add_commas(fb_count); $('#fb_count').html(fb_count); }); // grab from twitter var twitter = $.getJSON("https://twitter.com/users/"+t_page+".json?callback=?",function(data) { twit_count = data['followers_count'].toString(); twit_count_gt = data['followers_count'].toString(); twit_count = add_commas(twit_count); $('#twitter_count').html(twit_count); }); Thanks in advance!

    Read the article

  • Need help with jquery json data transfer from php file

    - by Scarface
    Hey guys I am trying to return the latest 10 results of a query from a php file, through json format, to a jquery getjson function that prints results. I am getting weird problems though. For example I am only getting 8 entries returned, and some are disordered, and sometimes nothing is returned. I am not really sure what I am doing wrong, so if anyone has any ideas I would really appreciate it. This is my query ($res) SELECT time, user, message FROM comments WHERE topic_id='$topic_id' ORDER BY time DESC LIMIT 10 This is the processing of the results while($row = mysql_fetch_array($res)){ $message=$row['message']; $user=$row['user']; if($row['message'] AND $row['time'] > $_GET['time']) $data[] = $row; } $out = json_encode($data); print $out; And this is the retrieval where prepare is just a function that returns information into a div $.getJSON(files+"processing.php?action=load&time="+0+"&topic_id="+topic_id+"&t=" + (new Date()), function(json) { if(json.length) { for(i=0; i < 10; i++) { $('#comment-list').prepend(prepare(json[i])); $('#list-' + count).fadeIn(1500); } } }); function prepare(response) { count++; var string = '<li class="comment-list" id="list-'+count+'">' //organize info into a div +'</li>'; return string; }

    Read the article

  • Very weird jquery/json problem...

    - by Scarface
    Hey guys I have finally located the cause of this problem...I just have no idea how to fix it and why it is happening. I have a jquery getjson function and it returns 0 results every 2-5 clicks on new topics or refreshes. For some reason if I change my query to sort results by ASC it always returns results and much quicker, but this poses a problem since I need results by DESC. If anyone has any ideas, I would greatly appreciate it because I am dumbfounded at this point. Here is my query but I need it by DESC SELECT time, user, message FROM comments WHERE topic_id='$topic_id' ORDER BY time ASC LIMIT 10 $.getJSON(files+"comments.php?action=view&load=initial&topic_id="+topic_id+"&t=" + (new Date()), function(json) { if(json.length) { for(i=0; i < json.length; i++) { $('#comment-list').prepend(prepare(json[i])); $('#list-' + count).fadeIn(1500); } } }); I return results like so while($row = mysql_fetch_array($res)){ $data[] = $row; } $out = json_encode($data); print $out;

    Read the article

  • Carscading dropdowns

    - by SnowJim
    Hi! I am working with carscading dropdowns in MVC. It apears that I will not be able to easaly create dropdowns on demand, instead I will have to add the dropdowns before sending it to the client. This is how are doing it right now : In the aspx page <%: Html.DropDownListFor(model => model.ModelViewAd.Category1, Model.ModelViewAd.Category1List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category2, Model.ModelViewAd.Category2List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category3, Model.ModelViewAd.Category3List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category4, Model.ModelViewAd.Category4List, "-- Välj kategori --")%> This is rendered like this : <select id="ModelViewAd_Category1" name="ModelViewAd.Category1"> <option value="">-- V&#228;lj kategori --</option> <option value="10">Fordon</option> <option value="15">F&#246;r hemmet</option> <option value="17">Bostad</option> </select> <select id="ModelViewAd_Category2" name="ModelViewAd.Category2"> <option value="">-- V&#228;lj kategori --</option> </select> <select id="ModelViewAd_Category3" name="ModelViewAd.Category3"> <option value="">-- V&#228;lj kategori --</option> </select> <select id="ModelViewAd_Category4" name="ModelViewAd.Category4"> <option value="">-- V&#228;lj kategori --</option> </select> This is how the script on the page looks like : <script type="text/javascript"> $(function () { $("select#ModelViewAd_Category1").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category2").addItems(data.d); }); }); $("select#ModelViewAd_Category2").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category3").addItems(data.d); }); }); $("select#ModelViewAd_Category3").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category4").addItems(data.d); }); }); }); </script> And then I have a included file that contains this : $.fn.clearSelect = function () { return this.each(function () { if (this.tagName == 'SELECT') this.options.length = 0; }); } $.fn.addItems = function (data) { return this.clearSelect().each(function () { if (this.tagName == 'SELECT') { var dropdownList = this; $.each(data, function (index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { dropdownList.add(option); } else { dropdownList.add(option, null); } if ($(this).children().size() < 2) { $(this).hide(); } else { $(this).show(); } }); } }); } The problem I now have is that I need to hide the dropdowns that do not contain any options or do only contains one option. This should be checked when doing a call to the service as well as when the page is sent to the client ("POSTBACK"). What I need is : 4 Dropdowns Only the first dropdown is visible when first entering the page. When selecting a option from dropdown1 the dropdown2 will be populated and so on If there is only 1 option then the dropdown should be hidden If all 4 dropdowns is set and the end-user change dropdown 1, then dropdown2 should be reloaded and the rest be hidden If the user have selected some of the dropdowns(say 1,2 and 3) and hit submit and the page is not accepted on the server side(not valid) the dropdowns should be set exacly as when the user cliked the submit button when the page returns to the user. Any suggestions on this?

    Read the article

  • Cascading dropdowns

    - by SnowJim
    Hi! I am working with cascading dropdowns in MVC. It appears that I will not be able to easily create dropdowns on demand, instead I will have to add the dropdowns before sending it to the client. This is how I am doing it right now: In the aspx page <%: Html.DropDownListFor(model => model.ModelViewAd.Category1, Model.ModelViewAd.Category1List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category2, Model.ModelViewAd.Category2List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category3, Model.ModelViewAd.Category3List, "-- Välj kategori --")%> <%: Html.DropDownListFor(model => model.ModelViewAd.Category4, Model.ModelViewAd.Category4List, "-- Välj kategori --")%> This is rendered like this : <select id="ModelViewAd_Category1" name="ModelViewAd.Category1"> <option value="">-- V&#228;lj kategori --</option> <option value="10">Fordon</option> <option value="15">F&#246;r hemmet</option> <option value="17">Bostad</option> </select> <select id="ModelViewAd_Category2" name="ModelViewAd.Category2"> <option value="">-- V&#228;lj kategori --</option> </select> <select id="ModelViewAd_Category3" name="ModelViewAd.Category3"> <option value="">-- V&#228;lj kategori --</option> </select> <select id="ModelViewAd_Category4" name="ModelViewAd.Category4"> <option value="">-- V&#228;lj kategori --</option> </select> This is what the script on the page looks like: <script type="text/javascript"> $(function () { $("select#ModelViewAd_Category1").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category2").addItems(data.d); }); }); $("select#ModelViewAd_Category2").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category3").addItems(data.d); }); }); $("select#ModelViewAd_Category3").change(function () { var id = $(this).val(); var urlAction = "/AdCategory/GetCategoriesByParent1/" + id; $.getJSON(urlAction, { id: id }, function (data) { $("#ModelViewAd_Category4").addItems(data.d); }); }); }); </script> And then I have an included file that contains this: $.fn.clearSelect = function () { return this.each(function () { if (this.tagName == 'SELECT') this.options.length = 0; }); } $.fn.addItems = function (data) { return this.clearSelect().each(function () { if (this.tagName == 'SELECT') { var dropdownList = this; $.each(data, function (index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { dropdownList.add(option); } else { dropdownList.add(option, null); } if ($(this).children().size() < 2) { $(this).hide(); } else { $(this).show(); } }); } }); } The problem I now have is that I need to hide the dropdowns that do not contain any options or only contain one option. This should be checked when doing a call to the service as well as when the page is sent to the client ("POSTBACK"). What I need is : 4 Dropdowns Only the first dropdown is visible when first entering the page. When selecting an option from dropdown1 the dropdown2 will be populated and so on If there is only 1 option then the dropdown should be hidden If all 4 dropdowns are set and the end-user changes dropdown1, then dropdown2 should be reloaded and the rest be hidden If the user has selected some of the dropdowns (say 1, 2 and 3) and hit submit and the page is not accepted on the server side (not valid) the dropdowns should be set exactly as when the user clicked the submit button when the page returns to the user. Any suggestions on this?

    Read the article

  • Merging multiple Google calendar feeds into one JSON object in javascript

    - by Jeramy
    I am trying to bring in the JSON feeds from multiple Google calendars so that I can sort the upcoming events and display the next X number in an "Upcoming Events" list. I have this working with Yahoo! pipes but I want to get away from using a 3rd party to aggregate. I think I am close, but I cannot get the JSON objects created correctly. I am getting the data into the array but not in JSON format, so I can't manipulate it. I have tried var myJsonString = JSON.stringify(JSONData); using https://github.com/douglascrockford/JSON-js but that just threw errors. I suspect because my variable is in the wrong starting format. I have tried just calling the feed like: $.getJSON(url); and creating a function concant1() to do the JSONData=JSONData.concat(data);, but it doesn't fire and I think it would produce the same end result anyway. I have also tried several other methods of getting the end result I want with varying degrees of doom. Here is the closest I have come so far: var JSONData = new Array(); var urllist = ["https://www.google.com/calendar/feeds/dg61asqgqg4pust2l20obgdl64%40group.calendar.google.com/public/full?orderby=starttime&max-results=3&sortorder=ascending&futureevents=true&ctz=America/New_York&singleevents=true&alt=json&callback=concant1","https://www.google.com/calendar/feeds/5oc3kvp7lnu5rd4krg2skcu2ng%40group.calendar.google.com/public/full?orderby=starttime&max-results=3&sortorder=ascending&futureevents=true&ctz=America/New_York&singleevents=true&alt=json&callback=concant1","http://www.google.com/calendar/feeds/rine4umu96kl6t46v4fartnho8%40group.calendar.google.com/public/full?orderby=starttime&max-results=3&sortorder=ascending&futureevents=true&ctz=America/New_York&singleevents=true&alt=json&callback=concant1"]; urllist.forEach(function addFeed(url){ alert("The URL being used: "+ url); if (void 0 != JSONData){JSONData=JSONData.concat($.getJSON(url));} else{JSONData = $.getJSON(url);} alert("The count from concantonated JSONData: "+JSONData.length); }); document.write("The final count from JSONData: "+JSONData.length+"<p>"); console.log(JSONData) UPDATE: Now with full working source!! :) If anyone would like to make suggestions on how to improve the code's efficiency it would be gratefully accepted. I hope others find this useful.: // GCal MFA - Google Calendar Multiple Feed Aggregator // Useage: GCalMFA(CIDs,n); // Where 'CIDs' is a list of comma seperated Google calendar IDs in the format: [email protected], and 'n' is the number of results to display. // While the contained console.log(); outputs are really handy for testing, you will probably waant to remove them for regular usage // Author: Jeramy Kruser - http://jeramy.kruser.me //onerror=function (d, f, g){alert (d+ "\n"+ f+ "\n");} if (!window.console) {console = {log: function() {}};} document.body.className += ' js-enabled'; // Global variables var urllist = []; var maxResults = 3; // The default is 3 results unless a value is sent var JSONData = {}; var eventCount = 0; var errorLog = ""; JSONData = { count: 0, value : { description: "Aggregates multiple Google calendar feeds into a single sorted list", generator: "StackOverflow communal coding - Thanks for the assist Patrick M", website: "http://jeramy.kruser.me", author: "Jeramy & Kasey Kruser", items: [] }}; // For putting dates from feed into a format that can be read by the Date function for calculating event length. function parse (str) { // validate year as 4 digits, month as 01-12, and day as 01-31 str = str.match (/^(\d{4})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/); if (str) { // make a date str[0] = new Date ( + str[1], + str[2] - 1, + str[3]); // check if month stayed the same (ie that day number is valid) if (str[0].getMonth () === + str[2] - 1) { return str[0]; } } return undefined; } //For outputting to HTML function output() { var months, day_in_ms, summary, i, item, eventlink, title, calendar, where,dtstart, dtend, endyear, endmonth, endday, startyear, startmonth, startday, endmonthdayyear, eventlinktitle, startmonthday, length, curtextval, k; // Array of month names from numbers for page display. months = {'0':'January', '1':'February', '2':'March', '3':'April', '4':'May', '5':'June', '6':'July', '7':'August', '8':'September', '9':'October', '10':'November', '11':'December'}; // For use in calculating event length. day_in_ms = 24 * 60 * 60 * 1000; // Instantiate HTML Arrays. summary = []; for (i = 0; i < maxResults; i+=1 ) { //console.log("i: "+i+" < "+"maxResults: "+ maxResults); if (!(JSONData.value.items[i] === undefined)) { item = JSONData.value.items[i]; // Grabbing data for each event in the feed. eventlink = item.link[0]; title = item.title.$t; // Only display the calendar title if there is more than one calendar = ""; if (urllist.length > 1) { calendar = '<br />Calendar: <a href="https://www.google.com/calendar/embed?src=' + item.gd$who[0].email + '&ctz=America/New_York">' + item.author[0].name.$t + '<\/a> (<a href="https://www.google.com/calendar/ical/' + item.gd$who[0].email + '/public/basic.ics">iCal<\/a>)'; } // Grabbing event location, if entered. if ( item.gd$where[0].valueString !== "" ) { where = '<br />' + (item.gd$where[0].valueString); } else { where = (""); } // Grabbing start date and putting in form YYYYmmdd. Subtracting one day from dtend to fix Google's habit of ending an all-day event at midnight on the following day. dtstart = new Date(parse(((item.gd$when[0].startTime).substring(0,10)).replace(/-/g,""))); dtend = new Date(parse(((item.gd$when[0].endTime).substring(0,10)).replace(/-/g,"")) - day_in_ms); // Put dates in pretty form for display. endyear = dtend.getFullYear(); endmonth = months[dtend.getMonth()]; endday = dtend.getDate(); startyear = dtstart.getFullYear(); startmonth = months[dtstart.getMonth()]; startday = dtstart.getDate(); //consolidate some much-used variables for HTML output. endmonthdayyear = endmonth + ' ' + endday + ', ' + endyear; eventlinktitle = '<a href="' + eventlink + '">' + title + '<\/a>'; startmonthday = startmonth + ' ' + startday; // Calculates the number of days between each event's start and end dates. length = ((dtend - dtstart) / day_in_ms); // HTML for each event, depending on which div is available on the page (different HTML applies). Only one div can exist on any one page. if (document.getElementById("homeCalendar") !== null ) { // If the length of the event is greater than 0 days, show start and end dates. if ( length > 0 && startmonth !== endmonth && startday === endday ) { summary[i] = ('<h3>' + eventlink + '">' + startmonthday + ', ' + startyear + ' - ' + endmonthdayyear + '<\/a><\/h3><p>' + title + '<\/p>'); } // If the length of the event is greater than 0 and begins and ends within the same month, shorten the date display. else if ( length > 0 && startmonth === endmonth && startyear === endyear ) { summary[i] = ('<h3><a href="' + eventlink + '">' + startmonthday + '-' + endday + ', ' + endyear + '<\/a><\/h3><p>' + title + '<\/p>'); } // If the length of the event is greater than 0 and begins and ends within different months of the same year, shorten the date display. else if ( length > 0 && startmonth !== endmonth && startyear === endyear ) { summary[i] = ('<h3><a href="' + eventlink + '">' + startmonthday + ' - ' + endmonthdayyear + '<\/a><\/h3><p>' + title + '<\/p>'); } // If the length of the event is less than one day (length < = 0), show only the start date. else { summary[i] = ('<h3><a href="' + eventlink + '">' + startmonthday + ', ' + startyear + '<\/a><\/h3><p>' + title + '<\/p>'); } } else if (document.getElementById("allCalendar") !== null ) { // If the length of the event is greater than 0 days, show start and end dates. if ( length > 0 && startmonth !== endmonth && startday === endday ) { summary[i] = ('<li>' + eventlinktitle + '<br />' + startmonthday + ', ' + startyear + ' - ' + endmonthdayyear + where + calendar + '<br />&#160;<\/li>'); } // If the length of the event is greater than 0 and begins and ends within the same month, shorten the date display. else if ( length > 0 && startmonth === endmonth && startyear === endyear ) { summary[i] = ('<li>' + eventlinktitle + '<br />' + startmonthday + '-' + endday + ', ' + endyear + where + calendar + '<br />&#160;<\/li>'); } // If the length of the event is greater than 0 and begins and ends within different months of the same year, shorten the date display. else if ( length > 0 && startmonth !== endmonth && startyear === endyear ) { summary[i] = ('<li>' + eventlinktitle + '<br />' + startmonthday + ' - ' + endmonthdayyear + where + calendar + '<br />&#160;<\/li>'); } // If the length of the event is less than one day (length < = 0), show only the start date. else { summary[i] = ('<li>' + eventlinktitle + '<br />' + startmonthday + ', ' + startyear + where + calendar + '<br />&#160;<\/li>'); } } } if (summary[i] === undefined) { summary[i] = "";} //console.log(summary[i]); } console.log(JSONData); // Puts the HTML into the div with the appropriate id. Each page can have only one. if (document.getElementById("homeCalendar") !== null ) { curtextval = document.getElementById("homeCalendar"); console.log("homeCalendar: "+curtextval); } else if (document.getElementById("oneCalendar") !== null ) { curtextval = document.getElementById("oneCalendar"); console.log("oneCalendar: "+curtextval); } else if (document.getElementById("allCalendar") !== null ) { curtextval = document.getElementById("allCalendar"); console.log("allCalendar: "+curtextval); } if (curtextval.innerHTML.length < 100) { errorLog += '<div id="noEvents">No events found.</div>'; } for (k = 0; k<maxResults; k+=1 ) { curtextval.innerHTML = curtextval.innerHTML + summary[k]; } if (eventCount === 0) { errorLog += '<div id="noEvents">No events found.</div>'; } if (document.getElementById("homeCalendar") === null ) { curtextval.innerHTML = '<ul>' + curtextval.innerHTML + '<\/ul>'; } if (errorLog !== "") { curtextval.innerHTML += errorLog; } } // For taking in each feed, breaking out the events and sorting them into the object by date function sortFeed(event) { var tempEntry, i; tempEntry = event; i = 0; console.log("*** New incoming event object #"+eventCount+" ***"); console.log(event.title.$t); console.log(event); //console.log("i = " + i + " and maxResults " + maxResults); while(i<maxResults) { console.log("i = " + i + " < maxResults " + maxResults); console.log("Sorting event = " + event.title.$t + " by date of " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"")); if (JSONData.value.items[i]) { console.log("JSONData.value.items[" + i + "] exists and has a startTime of " + JSONData.value.items[i].gd$when[0].startTime.substring(0,10).replace(/-/g,"")); if (event.gd$when[0].startTime.substring(0,10).replace(/-/g,"")<JSONData.value.items[i].gd$when[0].startTime.substring(0,10).replace(/-/g,"")) { console.log("The incoming event value of " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"") + " is < " + JSONData.value.items[i].gd$when[0].startTime.substring(0,10).replace(/-/g,"")); tempEntry = JSONData.value.items[i]; console.log("Existing JSONData.value.items[" + i + "] value " + JSONData.value.items[i].gd$when[0].startTime.substring(0,10).replace(/-/g,"") + " stored in tempEntry"); JSONData.value.items[i] = event; console.log("Position JSONData.value.items[" + i + "] set to new value: " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"")); event = tempEntry; console.log("Now sorting event = " + event.title.$t + " by date of " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"")); } else { console.log("The incoming event value of " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"") + " is > " + JSONData.value.items[i].gd$when[0].startTime.substring(0,10).replace(/-/g,"") + " moving on..."); } } else { JSONData.value.items[i] = event; console.log("JSONData.value.items[" + i + "] does not exist so it was set to the Incoming value of " + event.gd$when[0].startTime.substring(0,10).replace(/-/g,"")); i = maxResults; } i += 1; } } // For completing the aggregation function complete(result) { var str, j, item; // Track the number of calls completed back, we're not done until all URLs have processed if( complete.count === undefined ){ complete.count = urllist.length; } console.log("complete.count = "+complete.count); console.log(result.feed); if(result.feed.entry){ JSONData.count = maxResults; // Check each incoming item against JSONData.value.items console.log("*** Begin Sorting " + result.feed.entry.length + " Events ***"); //console.log(result.feed.entry); result.feed.entry.forEach( function(event){ eventCount += 1; sortFeed(event); } ); } if( (complete.count-=1)<1 ) { console.log("*** Done Sorting ***"); output(); } } // This is the main function. It takes in the list of Calendar IDs and the number of results to display function GCalMFA(list,results){ var i, calPreProperties, calPostProperties1, calPostProperties2; calPreProperties = "https://www.google.com/calendar/feeds/"; calPostProperties1 = "/public/full?max-results="; calPostProperties2 = "&orderby=starttime&sortorder=ascending&futureevents=true&ctz=America/New_York&singleevents=true&alt=json&callback=?"; if (list) { if (results) { maxResults = results; } urllist = list.split(','); for (i = 0; i < urllist.length; i+=1 ){ if (urllist[i] === 0){ urllist.splice(i,1);} else{ urllist[i] = calPreProperties + urllist[i] + calPostProperties1+maxResults+calPostProperties2;} } console.log("There are " + urllist.length + " URLs"); urllist.forEach(function addFeed(url){ $.getJSON(url, complete); }); } else { errorLog += '<div id="noURLs">No calendars have been selected.</div>'; output(); } }

    Read the article

  • ASP.NET Web API - Screencast series Part 4: Paging and Querying

    - by Jon Galloway
    We're continuing a six part series on ASP.NET Web API that accompanies the getting started screencast series. This is an introductory screencast series that walks through from File / New Project to some more advanced scenarios like Custom Validation and Authorization. The screencast videos are all short (3-5 minutes) and the sample code for the series is both available for download and browsable online. I did the screencasts, but the samples were written by the ASP.NET Web API team. In Part 1 we looked at what ASP.NET Web API is, why you'd care, did the File / New Project thing, and did some basic HTTP testing using browser F12 developer tools. In Part 2 we started to build up a sample that returns data from a repository in JSON format via GET methods. In Part 3, we modified data on the server using DELETE and POST methods. In Part 4, we'll extend on our simple querying methods form Part 2, adding in support for paging and querying. This part shows two approaches to querying data (paging really just being a specific querying case) - you can do it yourself using parameters passed in via querystring (as well as headers, other route parameters, cookies, etc.). You're welcome to do that if you'd like. What I think is more interesting here is that Web API actions that return IQueryable automatically support OData query syntax, making it really easy to support some common query use cases like paging and filtering. A few important things to note: This is just support for OData query syntax - you're not getting back data in OData format. The screencast demonstrates this by showing the GET methods are continuing to return the same JSON they did previously. So you don't have to "buy in" to the whole OData thing, you're just able to use the query syntax if you'd like. This isn't full OData query support - full OData query syntax includes a lot of operations and features - but it is a pretty good subset: filter, orderby, skip, and top. All you have to do to enable this OData query syntax is return an IQueryable rather than an IEnumerable. Often, that could be as simple as using the AsQueryable() extension method on your IEnumerable. Query composition support lets you layer queries intelligently. If, for instance, you had an action that showed products by category using a query in your repository, you could also support paging on top of that. The result is an expression tree that's evaluated on-demand and includes both the Web API query and the underlying query. So with all those bullet points and big words, you'd think this would be hard to hook up. Nope, all I did was change the return type from IEnumerable<Comment> to IQueryable<Comment> and convert the Get() method's IEnumerable result using the .AsQueryable() extension method. public IQueryable<Comment> GetComments() { return repository.Get().AsQueryable(); } You still need to build up the query to provide the $top and $skip on the client, but you'd need to do that regardless. Here's how that looks: $(function () { //--------------------------------------------------------- // Using Queryable to page //--------------------------------------------------------- $("#getCommentsQueryable").click(function () { viewModel.comments([]); var pageSize = $('#pageSize').val(); var pageIndex = $('#pageIndex').val(); var url = "/api/comments?$top=" + pageSize + '&$skip=' + (pageIndex * pageSize); $.getJSON(url, function (data) { // Update the Knockout model (and thus the UI) with the comments received back // from the Web API call. viewModel.comments(data); }); return false; }); }); And the neat thing is that - without any modification to our server-side code - we can modify the above jQuery call to request the comments be sorted by author: $(function () { //--------------------------------------------------------- // Using Queryable to page //--------------------------------------------------------- $("#getCommentsQueryable").click(function () { viewModel.comments([]); var pageSize = $('#pageSize').val(); var pageIndex = $('#pageIndex').val(); var url = "/api/comments?$top=" + pageSize + '&$skip=' + (pageIndex * pageSize) + '&$orderby=Author'; $.getJSON(url, function (data) { // Update the Knockout model (and thus the UI) with the comments received back // from the Web API call. viewModel.comments(data); }); return false; }); }); So if you want to make use of OData query syntax, you can. If you don't like it, you're free to hook up your filtering and paging however you think is best. Neat. In Part 5, we'll add on support for Data Annotation based validation using an Action Filter.

    Read the article

  • Introducing jLight &ndash; Talking to the DOM using Silverlight and jQuery.

    - by Timmy Kokke
    Introduction With the recent news about Silverlight on the Windows Phone and all the great Out-Of-Browser features in the upcoming Silverlight 4 you almost forget Silverlight is a browser plugin. It most often runs in a web browser and often as a control. In many cases you need to communicate with the browser to get information about textboxes, events or details about the browser itself. To do this you can use JavaScript from Silverlight. Although Silverlight works the same on every browser, JavaScript does not and it won’t be long before problems arise. To overcome differences in browser I like to use jQuery. The only downside of doing this is that there’s a lot more code needed that you would normally use when you write jQuery in JavaScript. Lately, I had to catch changes is the browser scrollbar and act to the new position. I also had to move the scrollbar when the user dragged around in the Silverlight application. With jQuery it was peanuts to get and set the right attributes, but I found that I had to write a lot of code on Silverlight side.  With a few refactoring I had a separated out the plumbing into a new class and could call only a few methods on that to get the same thing done. The idea for jLight was born. jLight vs. jQuery The main purpose of jLight is to take the ease of use of jQuery and bring it into Silverlight for handling DOM interaction. For example, to change the text color of a DIV to red, in jQuery you would write: jQuery("div").css("color","red"); In jLight the same thing looks like so: jQuery.Select("div").Css("color","red");   Another example. To change the offset in of the last SPAN you could write this in jQuery : jQuery("span:last").offset({left : 10, top : 100});   In jLight this would do the same: jQuery.Select("span:last").Offset(new {left = 10, top = 100 });   Callbacks Nothing too special so far. To get the same thing done using the “normal” HtmlPage.Window.Eval, it wouldn’t require too much effort. But to wire up a handler for events from the browser it’s a whole different story. Normally you need to register ScriptMembers, ScriptableTypes or write some code in JavaScript. jLight takes care of the plumbing and provide you with an simple interface in the same way jQuery would. If you would like to handle the scroll event of the BODY of your html page, you’ll have to bind the event using jQuery and have a function call back to a registered function in Silverlight. In the example below I assume there’s a method “SomeMethod” and it is registered as a ScriptableObject as “RegisteredFromSilverlight” from Silverlight.   jQuery("body:first").scroll(function() { var sl = document.getElementbyId("SilverlightControl"); sl.content.RegisteredFromSilverlight.SomeMethod($(this)); });       Using jLight  in Silverlight the code would be even simpler. The registration of RegisteredFromSilverlight  as ScriptableObject can be omitted.  Besides that, you don’t have to write any JavaScript or evaluate strings with JavaScript.   jQuery.Select("body:first").scroll(SomeMethod);   Lambdas Using a lambda in Silverlight can make it even simpler.  Each is the jQuery equivalent of foreach in C#. It calls a function for every element found by jQuery. In this example all INPUT elements of the text type are selected. The FromObject method is used to create a jQueryObject from an object containing a ScriptObject. The Val method from jQuery is used to get the value of the INPUT elements.   jQuery.Select("input:text").Each((element, index) => { textBox1.Text += jQueryObject.FromObject(element).Val(); return null; });   Ajax One thing jQuery is often used for is making Ajax calls. Making calls to services to external services can be done from Silverlight, but as easy as using jQuery. As an example I would like to show how jLight does this. Below is the entire code behind. It searches my name on twitter and shows the result. This example can be found in the source of the project. The GetJson method passes a Silverlight JsonValue to a callback. This callback instantiates Twit objects and adds them to a ListBox called TwitList.   public partial class DemoPage2 : UserControl { public DemoPage2() { InitializeComponent(); jQuery.Load(); }   private void CallButton_Click(object sender, RoutedEventArgs e) { jQuery.GetJson("http://search.twitter.com/search.json?lang=en&q=sorskoot", Done); }   private void Done(JsonValue arg) { var tweets = new List<Twit>(); foreach (JsonObject result in arg["results"]) { tweets.Add(new Twit() { Text = (string)result["text"], Image = (string)result["profile_image_url"], User = (string)result["from_user"] } ); } TwitList.ItemsSource = tweets; } }   public class Twit { public string User { get; set; } public string Image { get; set; } public string Text { get; set; } }   Conclusion Although jLight is still in development it can be used already.There isn’t much documentation yet, but if you know jQuery jLight isn’t very hard to use.  If you would like to try it, please let me know what you think and report any problems you run in to. jLight can be found at:   http://jlight.codeplex.com

    Read the article

  • jQuery mobile List-View is not working after adding some jquery code [closed]

    - by Kaidul Islam Sazal
    I am using jquery mobile and I have an array makeArrayin jquery and I have created few listview by the values of the array.Everything works fine.But the jquery mobile list-view style is not shown. Rather it is shown an ordinary list view. This is my code: $(document).ready(function(){ var url = "inventory/inventory.json"; var makeArray = new Array(); $.getJSON(url, function(data){ $.each(data, function(index, item){ if(($.inArray(item.make, makeArray)) == -1){ makeArray.push(item.make); $('.upper_case') .append('<li data-icon="list-arrow"> <a href="trade_form.php?='+ item.make +'"><img src="images/car_logo/buick.png" class="ui-li-thumb"/>' + item.make + '</a></li>'); } }); }); });

    Read the article

  • When Googlebot sees a link, will it click it or navigate to it?

    - by FakeRainBrigand
    My site uses pushState and JSON data to display content. So, for example, this might appear on my page: <a href="/some/page">some page</a> The JavaScript then prevents the default action (following the link), and instead renders a view (using a different api, such as /getjson?some_page). $('[href]').click(function(){ history.pushState(...); handleURL(...); }); Assume my server will respond to requests at /some/page with a pre-rendered version. My questions are: will Googlebot receive the prerendered version, or allow JavaScript to instead invoke pushState, etc. if it doesn't make the direct request, will it wait for AJAX content to be loaded? does Googlebot implement pushState, so it will show the proper URL in search results?

    Read the article

  • Load external style sheets on request from a different origin

    - by AshTek
    Hi, Is there a plugin or feature in jQuery that enables the dynamic loading of stylesheets from different origins similar to $.getJSON() or $.getScript()? I am able to dynamically integrate a style sheet from the same origin, but I need to be able to dynamically inject a jQuery UI theme from a different origin into a page. I guess I can load the CSS file as JSON data and then apply the contents using $().css(); however, I was looking for a more elegant solution. Thanks

    Read the article

  • mvc2 migration issue

    - by Sefer KILIÇ
    i migrate my mvc1 project to mvc2. my jquery json result function does not work anymore. have any idea ? aspx $.getJSON('Customer/GetWarningList/0', function(jsonResult) { $.each(jsonResult, function(i, val) { $('#LastUpdates').prepend(jsonResult[i].Url); }); }); controller public JsonResult GetWarningList(string id) { List<WarningList> OldBck = new List<WarningList>(); return this.Json(OldBck); }

    Read the article

  • cant read the json fom yahoo pipe.

    - by Bunny Rabbit
    $(function(){ $.getJSON('http://pipes.yahoo.com/pipes/pipe.run?_id=7ba696f34ae17b6fa8f5d4de13064dea&_render=json&callback=?',function(data){alert('called')}); }); i am using the above code to acess the a yahoo pipe i created to convert the last.fm xml output to json.but the firebug console output is showing me invalid label http://pipes.yahoo.com/pipes/pipe.run?_id=7ba696f34ae17b6fa8f5d4de13064dea&_render=json&callback=jsonp1276401573015 Line 1 while i can view the result using a browser in a perfectly normal way.also i validated the json using jsonlint and it shows the json is valid,what migt be the problem ?

    Read the article

  • anonymous function variable scope [js, ajax]

    - by arthurprs
    $(".delete").click( function() { var thesender = this; $(thesender).text("Del..."); $.getJSON("ajax.php", {}, function(data) { if (data["result"]) $(thesender).remove(); // variable defined outside else alert('Error!'); } ); return false; } ); This can cause problems if user clicks on another ".delete" before the ajax callback is called?

    Read the article

  • jquery parse json

    - by Eeyore
    I can't parse the JSON that I have no control of. What am I doing wrong here? data.json { "img": "img1.jpg", "img": "img2.jpg", "size": [52, 97] } { "img": "img3.jpg", "img": "img4.jpg", "size": [52, 97] } jquery $.getJSON("data.json", function(data){ $.each(data, function(i,item){ alert(item.img[i]); }); });

    Read the article

  • How to update strongly typed Html.DropDownList using Jquery

    - by Remnant
    I have a webpage with two radiobuttons and a dropdownlist as follows: <div class="sectionheader">Course <div class="dropdown"><%=Html.DropDownList("CourseSelection", Model.CourseList, new { @class = "dropdown" })%> </div> <div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Advanced", false )%> Advanced </label></div> <div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Beginner", true )%> Beginner </label></div> </div> The dropdownlist is strongly typed and populated with Model.CourseList (NB - on the first page load, 'Beginner' is the default selection and the dropdown shows the beginner course options accordingly) What I want to be able to do is to update the DropDownList based on which radiobutton is selected i.e. if 'Advanced' selected then show one list of course options in dropdown, and if 'Beginner' selected then show another list of courses. The code I would like to call sits within my Controller: public JsonResult UpdateDropDown(string courseType) { IDropDownList dropdownlistRepository = new DropDownListRepository(); IEnumerable<SelectListItem> courseList = dropdownlistRepository.GetCourseList(courseType); return Json(courseList); } Edit - Updated below to show latest position Using examples provided in jQuery in Action, I now have the following jQuery code: $('.radiobuttons input:radio').click(function() { var courseType = $(this).val(); //Get selected courseType from radiobutton var dropdownList = $(".dropdown"); //Ref for dropdownlist $.getJSON("/ByCourse/UpdateDropDown", { courseType: courseType }, function(data) { $(dropdownList).loadSelect(data); }); }); The loadSelect function is taken straight from the book and is as follows: (function($) { $.fn.emptySelect = function() { return this.each(function() { if (this.tagName == 'SELECT') this.options.length = 0; }); } $.fn.loadSelect = function(optionsDataArray) { return this.emptySelect().each(function() { if (this.tagName == 'SELECT') { var selectElement = this; $.each(optionsDataArray, function(index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { selectElement.add(option); } else { selectElement.add(option, null); } }); } }); } })(jQuery); 1 day+ later I still cannot get this to work. Assuming the jQuery code is correct then I can only think that the issue is with retrieving the actual data with $getJSON. I have verified that JsonResult UpdateDropDown does actually retrieve valid data. What am I missing? Assembly reference? (NB: I have MicrosoftAjax.js and MicrosoftMvcAjax.js in my head tags of the master page Should JsonResult be ActionResult? (I have seen both used in samples on web) Do I need to register route Controller/UpdateDropDown in Global.asax? Any further guidance would be appreciated.

    Read the article

  • jQuery cannot retrieve data from localhost

    - by fatnic
    I have a very simple bit of jQuery to retrieve my latest Tweet $.getJSON("http://twitter.com/statuses/user_timeline/username.json?count=1", function(data) { $("#tweet_text").html(data[0].text); }); This works fine on a simple HTML file on my desktop. However, once the file is accessed from my localhost (apache) no data is being returned. I was wondering if any part of Apache was blocking the request somehow? Or any other ideas?

    Read the article

  • jQuery plugin to put a twitter feed on my site

    - by Horace Loeb
    I want to put the first n entries from my twitter feed on my blog with the usual enhancements: Convert URLs to real links Remove @ replies I realize this wouldn't be too difficult to code from scratch with $.getJSON, but since this sort of thing is so common, I was wondering if there was a neat plugin that would handle everything for me.

    Read the article

  • JavaScript: What would cause setInterval to stop firing?

    - by Rosarch
    I am writing a chat AJAX app. Randomly, in FF 3.5.9, setInterval() seems to stop firing. I don't have clearInterval() anywhere in my code. What could be causing this to happen? $(document).ready(function () { $("#no-js-warning").empty(); messageRefresher = new MessageRefresher(0); setInterval($.proxy(messageRefresher, "refresh"), 2000); }); function notifyInRoom(user) { $.getJSON('API/users_in_room', { room_id: $.getUrlVar('key'), username: user }, function (users) { if (!$.isEmptyObject(users)) { $("#users").empty(); $.each(users, function (index, username) { var newChild = sprintf("<li>%s</li>", username); $("#users").append(newChild); }); } else { $("#users-loading-msg").text("No one is in this room."); } }); } function MessageRefresher(latest_mid) { this._latest_mid = latest_mid; } MessageRefresher.prototype.refresh = function () { notifyInRoom($("#user-name").val()); var refresher = this; $.getJSON('API/read_messages', { room_id: $.getUrlVar('key'), mid: refresher._latest_mid }, function (messages) { if (! (messages == null || $.isEmptyObject(messages[0]))) { // messages will always be at least [[], [], 0] $("#messages-loading-msg").hide(); for (var i = 0; i < messages[0].length; i++) { var newChild = sprintf('<li><span class="username">%s:</span> %s</li>', messages[1][i], messages[0][i]); $("#messages").append(newChild); } refresher._latest_mid = messages[2]; setUserBlockClass(); } else { $("#messages-loading-msg").text("No messages here. Say anything..."); } }); } // Give the end-user-block class to the appropriate messages // eg, those where the next message is by a different user function setUserBlockClass() { $("#messages li").each(function (index) { if ($(this).children(".username").text() != $(this).next().children(".username").text()) { $(this).addClass("end-user-block"); } }); } I checked the most recent responses in Firebug, and it was the same responses that had been sent earlier. (So, it's not like an unusual response caused a crash.) If I refresh the page, the calls resume.

    Read the article

  • how to create a JSON object in action class of JAVA

    - by Jugal
    I want to create a JSON object. I have tried the following myString=new JSONObject().put("JSON", sampleClass).toString(); but mystring gives me {"SampleClass@170f98"}. I also tried the following XStream xsStream=new XStream(new JsonHierarchicalStreamDriver()); SampleClass sampleClass=new SampleClass(userset.getId(),userset.getUsername()); myString=xsStream.toXML(sampleClass); It works but when i use getJSON in javascript to get myString it does not work.

    Read the article

  • jQuery and AJAX what should I use?

    - by thedp
    Hello, I've decided to go with jQuery for all my AJAX related client side needs. But jQuery has way too many functions for the same task: $.post, $.get, $.ajax, $.getJSON... My question is what should I use? Thank you.

    Read the article

  • JSONResult to String

    - by Dustin Laine
    I have a JsonResult that is working fine, and returning JSON from some POCO's. I want to save the JSON as a string in a DB. public JsonResult GetJSON() { JsonResult json = new JsonResult { Data = GetSomPocos() }; return json; } I need to audit the response, so I want to save the json into a DB. I am having trouble finding a way to get the JSON as a string. Any help is appreciated.

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >