Created
September 27, 2012 14:28
-
-
Save batizhevsky/3794297 to your computer and use it in GitHub Desktop.
cross domain post with ajax
This file contains hidden or 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 crossDomainPost() { | |
// Add the iframe with a unique name | |
var iframe = document.createElement("iframe"); | |
var uniqueString = "CHANGE_THIS_TO_SOME_UNIQUE_STRING"; | |
document.body.appendChild(iframe); | |
iframe.style.display = "none"; | |
iframe.contentWindow.name = uniqueString; | |
// construct a form with hidden inputs, targeting the iframe | |
var form = document.createElement("form"); | |
form.target = uniqueString; | |
form.action = "http://INSERT_YOUR_URL_HERE"; | |
form.method = "POST"; | |
// repeat for each parameter | |
var input = document.createElement("input"); | |
input.type = "hidden"; | |
input.name = "INSERT_YOUR_PARAMETER_NAME_HERE"; | |
input.value = "INSERT_YOUR_PARAMETER_VALUE_HERE"; | |
form.appendChild(input); | |
document.body.appendChild(form); | |
form.submit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment