I am using a dropdown for marking messages are read, I have implemented it with ajax call, it is working fine on IE and Chrome but i am having issue in firefox, after reutrning data from my Controller, success function of below code has an argument name result, in IE and
Chrome it is working fine( i am sending its value true) but in case of firefox it is showing error msg(ReferenceError: result is not defined) i have checked this error on console. I am using Jquery’s version 1.6
$("#mark").change(function () {
var message = $('#move_folder').val();
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: '/Message/TakeActions'
+ '?message=' + message,
dataType: 'json',
data: $.toJSON(msgsData),
success: function (result) {
if (result == true) {
// window.location.href = "/inviteFriends/Index";
window.location.reload();
DivMsgText("Message moved successfully to" + message);
$("#selectall").removeAttr("checked");
for (var i = 0; i < $('.case').length; i++) {
if ($('.case')[i].checked)
$('.case')[i].checked = false;
}
}
else {
if (message == "mark_read") {
alert("Select a message to mark as read");
}
else {
// DivMsgText("Select a message to move");
alert("Select a message to move");
}
$("#divmsg").empty();
$("#divmsg").removeClass("success grid_9");
$("#divmsg").html().remove();
}
},
async: false,
cache: false
});
});
Try replacing the following loop:
with this:
Also make sure you properly URL encode your query string parameters:
Also you shouldn’t be using any javascript after
window.location.reload();. This function does what it name suggests: it reloads the page by navigating away from it which as a consequence might stop the execution of any subsequent js.Also try to return a valid JSON object from your
TakeActionscontroller action:and then on the client side use the following test:
The problem with your code is that I suspect you only returned true:
which sends the string
trueinto the response which is an invalid JSON string and yet you are telling jQuery that your server returns JSON by settingdataType: 'json'.And yet another remark: you seem to be using some
messagevariable which is not declared anywhere in the scope you have shown in your question. Is this variable actually declarzed somewhere? Is it declared in a scope which is accessible within your function?