You need to include a callback for your post, since with they way your code is now, it calls the post, but then just continues to execute the next command. I would just add an extra parameter to your function. Something like this:
function form(elem, callback) {
var dati = $(elem).serialize();
var action = $(elem).attr("action");
var result = "";
$.post(action, dati, function (data) {
result = jQuery.parseJSON(data);
callback(result);
});
}
$(document).on("submit", "#new-search-field", function () {
form($(this), function (data) { alert(data); });
if (......) {.....
}
});
Hope this helps