Skip to content

Instantly share code, notes, and snippets.

View toranb's full-sized avatar

Toran Billups toranb

View GitHub Profile
@toranb
toranb / basic_ajax.js
Created November 11, 2012 18:00
basic ajax to pull down json and do something in the success handler
$.ajax({
url: url,
dataType: "json",
success: function (response) {
//do something with the json data
}
});
@toranb
toranb / nieve_ajax.js
Created November 11, 2012 18:05
nieve ajax to pull down json and do something with remote data
$.ajax({
url: url + '?callback=someRandomCallback',
dataType: "json"
});
function someRandomCallback(response) {
//do something with the json data (this function must be global for this example)
}
@toranb
toranb / jsonp_ajax.js
Created November 11, 2012 18:13
true jsonp ajax to pull down json and do something with remote data
$.ajax({
url: url,
dataType: "jsonp",
crossDomain: true,
success: function (response) {
//do something with the json data
}
});
@toranb
toranb / iframe-http-post.js
Created November 11, 2012 18:56
cross domain multipart post for file upload
var iframeId = 'somethingUnique';
var url = 'http://someotherdomain.com';
var $form = $('<form>');
$form.attr('id', 'foo');
theForm.attr('action', url);
$('<iframe name="' + iframeId + '" id="' + iframeId + '" />').appendTo('body');
$("#" + attachment_id).attr('style', 'display: none;');
$("#" + attachment_id).append($form);
theForm.attr('target', iframeId);
theForm.attr('method', 'POST');
@toranb
toranb / iframe-http-post.js
Created November 11, 2012 18:57
cross domain multipart post for file upload
var iframeId = 'somethingUnique';
var url = 'http://someotherdomain.com';
var $form = $('<form>');
$form.attr('id', 'foo');
$form.attr('action', url);
$('<iframe name="' + iframeId + '" id="' + iframeId + '" />').appendTo('body');
$("#" + attachment_id).attr('style', 'display: none;');
$("#" + attachment_id).append($form);
$form.attr('target', iframeId);
$form.attr('method', 'POST');
@toranb
toranb / thanks-ie8.js
Created November 11, 2012 18:58
long hand dynamic form creation for ie8
var $form = $('<form>');
$form.attr('id', 'foo');
@toranb
toranb / broken-dynamic-form.js
Created November 11, 2012 18:59
short hand dynamic form creation that is broken in ie8
var $form = $('<form id="foo">');
@toranb
toranb / iframe-http-post.js
Created November 11, 2012 21:10
cross domain multipart post for file upload
var iframeId = 'somethingUnique';
var url = 'http://someotherdomain.com';
var $form = $('<form>');
$form.attr('id', 'foo');
$form.attr('action', url);
$('<iframe name="' + iframeId + '" id="' + iframeId + '" />').appendTo('body');
$("#" + iframeId).attr('style', 'display: none;');
$("#" + iframeId).append($form);
$form.attr('target', iframeId);
$form.attr('method', 'POST');
@toranb
toranb / append_remote_script.js
Created November 11, 2012 22:03
a very hacky way to achieve cross domain jsonp (w/out jQuery)
var url = 'http://someotherdomain.com?callback=someRandomCallback';
var remoteScript = document.createElement('script');
remoteScript.src = url;
document.body.appendChild(remoteScript);
function someRandomCallback(response) {
//do something with the json data (this function must be global for this example)
}
@toranb
toranb / app.js
Created December 3, 2012 02:20
basic jasmine-phantom-node express configuration
var express = require('express')
, http = require('http')
, app = express()
, server = http.createServer(app);
app.configure(function(){
app.use(express.static('/Users/toranb/foo/webapp'));
});
app.get('/', function(req, res) {