importment:
Return Json data to Ajax
Json(data, JsonRequestBehavior.AllowGet);
Jquery update Json result data
$("#email").text(result.email);
Debug:
console.log(result.status);
Controller
View
Ajax
[HttpPost]
public ActionResult editemail(string email)
{
bool result = false;
if (!string.IsNullOrWhiteSpace(email) && (EditEmail(hid, email)))
result = true;
var data = new { status = result, email = email };
return Json(data, JsonRequestBehavior.AllowGet);
}
View
<label id="lb_email">@(Model.UserData.email)</label> ]
Ajax
$.ajax({
url: '/rivatest/editemail/',
data: { email: email },
type: 'POST',
datatype:'json',
cache: false
}).success(function (result) {
//console.log(result);
if (result.status==true) {
$("#email").text(result.email);
}
else {
alert('Edit Email failed。');
}
console.log(result.status);
console.log(result.email);
}).error(function (result) {
alert(result);
});
沒有留言:
張貼留言