I have this JS code :
$(function () {
var newdata2;
$("form").submit(function (event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: "/MyController/Action1",
data: { nameid: $('#nameid').val() },
success: function (newdata) {
newdata2 = JSON.parse(newdata);
//doing other stuff...
When I call console.log(newdata) after this form.submit block, I get undefined. How can I get the value of newdata out of that block? Thanks in advance.