Trigger JQuery Dialog Box with JSON content ~ Andrew Pougher

Trigger JQuery Dialog Box with JSON content

by Andrew Pougher

HTML

<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css">
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css">
<button class='btn'>Launch Me</button>

JavaScript

$(".btn").live('touchstart click',function() {  
    $.post("/echo/json/",function(data){
 //in actuality the json will be parsed here
  var d = '{"id":"1","name":"Drew","age":41}';
    var json = $.parseJSON(d);
    $("<div/>",{text:json.name+" "+json.age}).appendTo("body");
    $("div").dialog();
 
},'json')
});