Skip to content

Instantly share code, notes, and snippets.

@RimonEkjon
Forked from bencooling/script.js
Created August 26, 2014 04:16
Show Gist options
  • Save RimonEkjon/225b9e77bf69cbd002ae to your computer and use it in GitHub Desktop.
Save RimonEkjon/225b9e77bf69cbd002ae to your computer and use it in GitHub Desktop.
jsonp workflow
$(function(){
var xhr, $form = $('form');
function getResponse(data){
console.log(data);
}
function postForm(){
return $.ajax({
'dataType' : "jsonp",
'data' : $form.serialize(),
'jsonp' : "emayll",
'url' : $form.attr('action')
})
}
$form.on('submit', function(e){
e.preventDefault();
xhr = postForm().done(getResponse);
return false;
});
});
<?php
// Handles JSONP requests
$app->get('/send', function() use($app) {
// Requires callback variable with name emayll
if ($cb = $app->request->get('emayll'))
echo $cb . '(' . json_encode($app->request->get()) . ');';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment