If I have a variable that needs to be posted to a PHP script without refreshing the page.
Is this possible? And if so, how?
My attempt using jQuery:
$.ajax({
url: "myphpfile.php",
type: "post",
data: json/array/whatever,
success: function(){ // trigger when request was successfull
window.location.href = 'somewhere'
}
})
How would I receive an array passed in my php script?
Use
GM_xmlhttpRequest()to allow for cross-domain posts (which it will be in most scenarios).Greasemonkey Script:
ShowJSON_PostedData.php:
The console. will show: