Not even sure if this is the right way to title the question. I know I’m making my AJAX calls all wrong… here’s what I’m doing right now (I’m using ASP.NET MVC backend by the way):
I use jQuery.ajax to post some data to an action, which will load a view that I capture in the response. It’s basically providing some data to an action, and taking some HTML back.
Let’s say I wanted to create an Ajax call that is validated. How do I get back the validation messages on error? For example, an Ajax login form. If the user cannot be validated, I’d like to tell them that… instead of simply doing nothing.
Sorry for the naive question, I just don’t know how to word it right to find the solutions on Google.
Thank you in advance!
First of all if you want AJAX call to return the data you are planning to use in your scripts (and by use I mean something more complicated then displaying that data in a
div), you should probably return JSON data instead of HTML from your server. JSON is actually a JS object so it can be used in JS the moment it is received.So if you return the data i.e.
You can use something like this to use that data.
});