Thiago, it seems a little strange to pass a json as a string to an API, especially by GET.
but you can consume this URL in two ways: AJAX or JSONP:
AJAX
var json = {
"login":"[email protected]",
"senha":"Minhasenha",
"campanha":"ID 1234",
"mensagens":{
"1":{
"numero":2799999999,
"msg":"Uma mensagem qualquer",
"data":new Date(2015, 9, 19, 1, 7, 52)
}
}
};
var data = new FormData();
data.append("data", JSON.stringify(json)):
var httpRequest = new XMLHttpRequest();
httpRequest.open("GET", "https://dominio.com/apiJSON.php", true);
httpRequest.responseType = "json";
httpRequest.addEventListener("readystatechange", function (event) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
console.log(httpRequest.response): //seu objeto JSON;
/* Faça alguma coisa com o "httpRequest.response" */
} else {
console.log("Ocorreu um Erro");
}
}
})
httpRequest.send(data);
JSONP
Note that I added another argument to your URL, callback=minhaFuncao
, the callback parameter defines the name of the function that will receive the json object obtained as return of the request.
var json = {
"login":"[email protected]",
"senha":"Minhasenha",
"campanha":"ID 1234",
"mensagens":{
"1":{
"numero":2799999999,
"msg":"Uma mensagem qualquer",
"data": new Date(2015, 9, 19, 1, 7, 52)
}
}
};
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://dominio.com/apiJSON.php?data=" + JSON.stringify(json) + "&callback=minhaFuncao";
var minhaFuncao = function(data) {
/* data é o objeto JSON retornado pelo script acima */
}
document.head.appendChild(script);
Vlw friend. I will try here and return you.
– Thiago