mercredi 14 janvier 2015

js variable definition for if statements

trying to teach myself js.


I have an ajax request I am running that returns data which includes some text and one number. The number is from a radio button list in a form and I'm trying to devise a scheme to handle the value so that:


text to be written in is determined by the following: if the number is 3, then it writes "not published" otherwise it writes "published"


text that to be written in is determined by the following: if the number is 0, it writes "in listings" if the number is 1, it writes "in recent transactions" if the number is 2, it writes "in listings and recent transactions"


The following is my script and it always prints "not published" and always prints "in listings and transactions" regardless of the value that's coming back to the page from my php script. the value is correct and I have these if statements working in php on another page but I need is in JS here.



$.ajax({
type: "POST",
dataType: "json",
url: "add-list.php",
data: formData,
success: function(response) {
if (response.success) {
$("#modal1").modal('hide');
$("#add_frame").show();
$(".azoning").html(response.zoninga);
var transdec = response.transactiona;
if (transdec=3) {$(".atrans").html("NOT PUBLISHED");} else {$(".atransaction").html("PUBLISHED");}
if (transdec=0) {$(".atransaction").html("in LISTINGS.");}
if (transdec=1) {$(".atransaction").html("in RECENT TRANSACTIONS");}
if (transdec=2) {$(".atransaction").html("in LISTINGS AND RECENT TRANSACTIONS");}

}
else {
console.log("An error has ocurred: sentence: " + response.sentence + "error: " + response.error);
}
},
contentType: false,
processData: false,
error: function() {
alert("An Error has ocurred contacting the server. Please contact your system administrator");
}
});


what's wrong with my js coding in this?


Aucun commentaire:

Enregistrer un commentaire