Created
May 9, 2012 09:01
-
-
Save slaporte/2643159 to your computer and use it in GitHub Desktop.
Using an iframe to post an anon edit to wp api
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
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