I have this code:
$.ajax({
type: 'get',
url: 'https://......./confirma.asp',
data: $('.newform').serialize(),
dataType: 'jsonp',
beforeSend: function () {
$('.ajax-loader').slideToggle();
},
success: function (resposta) {
alert(resposta); // not work
$('.ajax-loader').slideToggle();
}
});
I get this response from ajax GET (firebug):
CODRET=1&MSGRET=JA CONFIRMADA
How I get this values? For example:
resposta['CODRET'];
or
resposta.CODRET
Because I need set in another JQuery function( );
Well that looks like a query string. Here is a modified version of this answer:
function parseQueryString(qs) {
var urlParams = {};
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = qs.substring(1);
while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);
return urlParams;
}
console.log(parseQueryString("CODRET=1&MSGRET=JA CONFIRMADA"));
probably you should split them:
$.ajax({
type: 'get',
url: 'https://ecommerce.redecard.com.br/pos_virtual/confirma.asp',
data: $('.newform').serialize(),
beforeSend: function () {
$('.ajax-loader').slideToggle();
},
success: function (data) {
var codret = data.split('&')[0].split('=')[1];
var msgret = data.split('&')[1].split('=')[1];
$('.ajax-loader').slideToggle();
}
});
If you can't change the server code do this
function QueryStringToJsonObject(queryString)
{
var queries = {};
decodeURIComponent(queryString).replace(/([^=]+)=([^&]+)/g,
function(all, key, value) {
queries[key.replace(/^&/,'')] = value;
}
);
return queries;
}
and then:
QueryStringToJsonObject(responseText) ["CODRET"] //1
Otherwise consider returning JSON to http request.