Using a returned JSON like this:
[{"id":1,"name":"PHP"},{"id":2,"name":"CSS"},{"id":3,"name":"Javascript"}]
$('#parentSelectId').change(function { $.getJSON('http://example.com/ws/functionName?callback=?', function (data) { var select = $('#childrenSelectId'); var options = select.prop ? select.prop('options') : select.attr('options') ; $('option:not(:first)', select).remove(); $.each(data, function (index, array) { options[options.length] = new Option(array.name, array.id); }); }); });
Call this from any facebook app page. The secure page url must be set.
// ==UserScript== // @name Facebook Add Page Tab // @description Insert a link to add a page tab on facebook // @namespace dan // @include htt*://*.facebook.com/* // @match https://developers.facebook.com/apps/* // @exclude htt*://*channel*.facebook.com* // @exclude htt*://*static*.facebook.com* // @exclude htt*://upload.facebook.com/* // @exclude htt*://*.facebook.com/ajax/* // ==/UserScript== var appId = location.pathname.split('/')[2]; var appUrl = document.getElementById('secure_page_tab_url').value; var headMenu = document.getElementById('headerArea'); var link = document.createElement('a'); link.setAttribute('href', 'https://www.facebook.com/dialog/pagetab?app_id=' + appId + '&next=' + appUrl); link.setAttribute('target', '_blank'); link.appendChild(document.createTextNode('Agregar Tab')); headMenu.appendChild(link);
Bookmarklet:
javascript:(function(){var appId=location.pathname.split('/')[2];var appUrl=document.getElementById('secure_page_tab_url').value;var headMenu=document.getElementById('headerArea');if(appUrl==''){alert('Debes llenar el campo de "URL segura de la pesta%C3%B1a"');return false;}var link=document.createElement('a');link.setAttribute('href','https://www.facebook.com/dialog/pagetab?app_id='+appId+'&next='+appUrl);link.setAttribute('target','_blank');link.appendChild(document.createTextNode('Agregar Tab a Pagina'));headMenu.appendChild(link);})();