Skip to content

Instantly share code, notes, and snippets.

@slaporte
Created May 9, 2012 09:01
Show Gist options
  • Save slaporte/2643159 to your computer and use it in GitHub Desktop.
Save slaporte/2643159 to your computer and use it in GitHub Desktop.
Using an iframe to post an anon edit to wp api
var sendData = {
action: 'edit',
format: 'json',
title: 'User:Slaporte/sandbox',
text: 'test',
summary: 'test',
token: '+\\'
};
function iframe_post(url, data) {
// prepare the form
var iframe_form = '<h1>form loaded</h1><form id="editform" name="editform" method="post" action="' + url + '?title=' + data.title + '&action=edit&format=json" enctype="multipart/form-data"><input type="hidden" value="'+ data.token + '" name="token" /><input type="hidden" value="' + data.summary + '" name="summary" /><input type="hidden" name="text" value="' + data.text + '" />';
// does not work for a frame with cross domain content?
$('#post-frame').empty();
// add the frame
$('html').append('<iframe id="post-frame" width="2" height="2" style=""></iframe>');
$('#post-frame').contents().find('html').html(iframe_form);
// submit the form
$("#post-frame").contents().find('#editform').submit();
}
iframe_post('http://en.wikipedia.org/w/api.php', sendData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment