-
-
Save RimonEkjon/225b9e77bf69cbd002ae to your computer and use it in GitHub Desktop.
jsonp workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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