Nervius Nervius - 3 months ago 7
HTML Question

How to parse the return value and view an alert

function show(shown, hidden) {
console.log(shown,hidden)
$("#"+shown).show();
$("#"+hidden).hide();
}
$(".content-form").submit(function(){
var intRowCount = $(this).data('introwcount');
var exec ='show("Page"+data.result,"Page'+intRowCount+'")';
ajaxSubmit("/post.php", $(this).serialize(), "", exec,"json");
return false;
})
function ajaxSubmit(urlx, datax, loadingAppendToDiv, resultEval, dataTypex, completeEval) {
if (typeof dataTypex == "undefined") {
dataTypex = "html";
}
request = $.ajax({
type:'POST',
url: urlx,
dataType: dataTypex,
data: datax,
async: true,
beforeSend: function() {
$(".modalOverlay").show();
},
success: function(data, textStatus, jqXHR) {
loadingAppendToDiv !== "" ? $(loadingAppendToDiv).html(data) : "";
if (typeof resultEval !== "undefined") {
eval(resultEval);
} else {
}
},
error: function() {
alert('An error occurred. Data does not retrieve.');
},
complete: function() {
if (typeof completeEval !== "undefined") {
eval(completeEval);
} else {
}
$(".modalOverlay").hide();
}
});
}


My web service returns a value.I want to do,if my return value comes integer like 1,2,3,4 I want to hide my current page and open page which is come from result like 2. It's working but I want to add a if statement to parse the return string like "Question 1", it's mean Question 1 needed to be answer.How can I view an alert box like "You have to answer question 1"

Answer
if (data.result % 1 == 0){
 eval(resultEval);
 }
 else {
 var str = data.result
 console.log(str.substring(11,9999))
 var substr = (str.substring(11,9999))
 alert("Please answer question no = "+" "+substr)
 return false; }

add this on your code

Comments