Lil Josh

A tech blog about web development with PHP, MySQL, jQuery, CSS3 and various other programming languages. You will not find anything about ColdFusion, ASP.NET, C# on this blog.

jQuery JSONP Cross-domain AJAX Callback Function

August 29, 2014

There may be times where you need to make an AJAX call to a resource from another domain, but browsers will not allow a simple AJAX GET. Instead you’ll need to implement a callback function and use JSONP. Here’s an example of the requesting AJAX script:

var username = 'liljosh';
var url = '//'+username+'&output=json&callback=?';
$.getJSON(url, function (data) {

and the callbackScript.php could look like this:

output("Username is $_GET[username]");
// output as JSON
function output($html) {
if(isset($_GET['callback'])) $html = $_GET['callback'] . '(' . json_encode($html) . ')';
AJAX Callback Function Cross-domain jquery JSONP

Texting with PHP

June 6, 2014

Ever needed to text someone through PHP? It’s very simple! Most cellular providers give an email address with your phone number that can be used to text that number. This is known as “email to SMS gateway”. For example if my number is (555) 555-5555 and I used AT&T then emailing would send a text to my phone. So you can probably guess how the PHP looks, but here’s an example:

$from = "Lil Josh <>"; // sender
$subject = "Subject appears in the text message";
$message = "This is the contents of the text";
// send text message
mail("",$subject,$message,"From: $from\n"); // Verizon
mail("",$subject,$message,"From: $from\n"); // AT&T
mail("",$subject,$message,"From: $from\n"); // T-Mobile
mail("",$subject,$message,"From: $from\n"); // Virgin Mobile
mail("",$subject,$message,"From: $from\n"); // Sprint
mail("",$subject,$message,"From: $from\n"); // Nextel

For a more complete list of providers visit

AT&T Nextel PHP Sprint T-Mobile texting Verizon Virgin Mobile

Recursion in PHP

May 29, 2014

Using recursion can be a little hard to grasp if you are new to the concept. In it’s simplest form it’s a function that calls upon itself to create a loop. It is commonly used for traversing tree structures. This example shows PHP using recursion to get a list of all the child pages under a folder structure.

function getPages($folder, $pages=array()) {
//function returns everything in the folder 1 level
$assets = getChildren($folder); 
foreach($assets as $asset) {
if($asset->type == 'folder') {
$pages = getPages($asset->path, $pages);
} else if ($asset->type == 'page') {
array_push($pages, $asset->name);
return $pages;


example function PHP recursion

jQuery Mobile Dynamicly Appending to Listview via AJAX issue

March 9, 2014

With jQuery Mobile you can create a Listview of list items but I wanted to populate that list dynamically via AJAX. The problem I was getting is it would work fine when I loaded it the first time but then I wanted to nuke (clear) the list and repopulate it with new content. If you’ve gone through half the trouble I went through to get this to work then I know this is going to help you out! So I won’t drag this out any longer… here’s the solution:

//empty the list
//do some stuff to populate the content
myListContent += '<li><a>some content</a></li>';
//append the new content and create a new listview and refresh it
AJAX issue resolved jquery jquerymobile listview