w/JavaScript
//the callback function run after loading JSONp below
function test_results_loaded(data){
//post data to a service via ajax
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://orgnsm@orgnsm.org:lkAGWUE01H@orgnsm.testrail.com//index.php?/api/v2/add_result/1", true);
xhr.setRequestHeader('Content-Type', 'application/json;');
xhr.setRequestHeader('Accept', 'application/json;');
// send the collected data as JSON
xhr.send(JSON.stringify({"status_id":"1"}));
xhr.onloadend = function () { alert("Wrote test data"); };
}
window.onload = function(){
//add event to a button that loads remote JSONp
document.getElementById('loaderButton').onclick = function(){
var script = document.createElement('script');
script.src = 'http://shellfiche.anoml.net/test.php5?callback=test_results_loaded';
document.getElementsByTagName('head')[0].appendChild(script);
}
}
w/JQuery
$(document).ready(function(){
$("#loaderButton").click(function(){
$.ajax({
url: 'http://shellfiche.anoml.net/test.php5',
dataType: "jsonp",
jsonpCallback: "callback",
success: function( testreply ){
alert("Test results obtained.. Posting results...");
$.ajax({
url: 'https://orgnsm.testrail.com//index.php?/api/v2/add_result/1',
username: "orgnsm@orgnsm.org",
password: "lkAGWUE01H",
contentType: "application/json;",
accepts: "application/json;",
dataType: "json",
type: "POST",
data: '{"status_id": "1"}',
processData: "false",
headers:{"Content-Type": "application/json;"},
beforeSend: function(jqXHR){
jqXHR.overrideMimeType("application/json;");
jqXHR.setRequestHeader("Accept", "application/json;");
},
success: function( postreply ){
alert("Wrote test data");
}
});
}
});
return false;
});
});