I've been trying to debug an ajax call with chrome and firefox. I'm newbie in both. When debbuging with chrome, I was getting an ajax response with the two last params (jqXHR, textStatus, errorThrown)
empty and the first one was xhr status 0. I said sometimes, because I was getting some times an xhr status 200, and the params textStatus, errorThrown
was printing parse error, and unexpected character '<'. I've been looking at my php code and this '<' is nowere because I've been doing a test: to comment every php code and to return the same $_POST['json']
that php is getting from the ajax call, and I was getting the same errors. I've been looking at my json and is well formed. Confused by all these errors and confusing debug tools that I don't understand very well, I moved to firefox and firebug, and there I get another diferent message: "uncaught exception: out of memory"
I've been reading some others developers asking the same question, and tryed the accepted answers but I still can't find the issue, that's why I post my code here, hoping somebody can help. Thanks a lot!
html code:
<input type="submit" data-effect="mfp-zoom-out" value='Submit' onClick="setTypeAdvanced()" style= "
position: relative;
top: -152px;
left: 129px;
" />
jscript code in index.js:
function setTypeAdvanced(){
var advancedFormVars = {};
/**SHOW*/
if(document.getElementById('OfferID').checked == true){
advancedFormVars['checkbox1'] = document.getElementById('OfferID').value;
}
if(document.getElementById('offerName').checked == true){
advancedFormVars['checkbox2'] =document.getElementById('offerName').value;
}
if(document.getElementById('campaignID').checked == true){
advancedFormVars['checkbox3'] = document.getElementById('campaignID').value;
}
if(document.getElementById('campaignName').checked == true){
advancedFormVars['checkbox4'] = document.getElementById('campaignName').value;
}
if(document.getElementById('installs').checked == true){
advancedFormVars['checkbox5'] = document.getElementById('installs').value;
}
if(document.getElementById('revenue').checked == true){
advancedFormVars['checkbox6'] = document.getElementById('revenue').value;
}
/** FILTERS */
if(document.getElementById('offerIDFilt').checked == true){
advancedFormVars['checkbox7'] = document.getElementById('offerIDFilt').value;
}
if(document.getElementById('publisherIDFilt').checked == true){
advancedFormVars['checkbox8'] = document.getElementById('publisherIDFilt').value;
}
if(document.getElementById('publisherIDTextVal').value.length >'0'){
advancedFormVars['checkbox9'] = document.getElementById('publisherIDTextVal').value;
publisherIDTextVal = document.getElementById('publisherIDTextVal').value;
}
if(document.getElementById('offIDTextVal').value.length > '0'){
advancedFormVars['checkbox10'] = document.getElementById('offIDTextVal').value;
}
/**GROUP BY*/
if(document.getElementById('dates').checked == true){
advancedFormVars['checkbox11'] = document.getElementById('dates').value;
}
if(document.getElementById('geos').checked == true){
advancedFormVars['checkbox12'] = document.getElementById('geos').value;
}
if(document.getElementById('browsers').checked == true){//arreglar no coge checked, coge objeto html
advancedFormVars['checkbox13']= document.getElementById('browsers').value;
}
if(document.getElementById('oS').checked == true){//arreglar coge undefined
advancedFormVars['checkbox14'] = document.getElementById('oS').value;
}
/**ORDER BY*/
if(document.getElementById('installsGroupBy').checked == true){
advancedFormVars['checkbox15']= document.getElementById('installsGroupBy').value;
}
if(document.getElementById('revenueGroupBy').checked == true){
advancedFormVars['checkbox16']= document.getElementById('revenueGroupBy').value;
}
advancedFormVars['none']= (typeof none=== 'undefined') ? 'default' : none;
advancedFormVars['ASC']= (typeof ASC === 'undefined') ? 'default' : ASC;
advancedFormVars['DESC']= (typeof DESC === 'undefined') ? 'default' : DESC;
loadFormAdvanced(advancedFormVars);
}
function loadFormAdvanced(advancedFormVars){
var json = JSON.stringify(advancedFormVars);
$.ajax({
url : 'AL_loadForm.php',
type : 'POST',
data : {
json:json
},
dataType:'json',
success : function(data) {
alert(data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert('error '+errorThrown);
alert('status '+textStatus);
alert('xhr status '+jqXHR.status);
}
});
}
edit to add my php code:
<?php
if($_POST){
if($_POST['json']){
echo json_encode($_POST['json']); //also tryed echo($_POST['json']);
}
}
?>
And this is my json:
{"checkbox1":"OfferID","checkbox2":"Offer Name","checkbox3":"CampaignID","checkbox4":"CampaignName","checkbox5":"Installs","checkbox6":"Revenue","checkbox7":"OfferID","checkbox8":"PublisherID","checkbox9":"some publisher","checkbox10":"some offer","checkbox12":"Geos","checkbox15":"Installs","none":"default","ASC":"default","DESC":"default"}
it has been copy/pasted from console log right before beeing sended in the ajax call:
var json = JSON.stringify(advancedFormVars);
console.log(json);
$.ajax({
url : 'AL_loadForm.php',
type : 'POST',
data : {
json:json
},
dataType:'json',
success : function(data) {
alert(data);