As I learned so far, client-side AJAX script can read a static .json or .xml file from server e.g. http://www.mydomain.com/all_cities.xml.
But I need to generate a .json or .xml file dynamically according to the user input at client-side. e.g. imagine that the user selects a state from DropDownList1 and AJAX should fill DropDownList2 with that state’s cities; while I don’t like to send all cities and then filtering desired cities in client-side!
So, I would like to know how ASP.NET can handle this e.g. when it sees “http://www.mydomain.com/cities.json?state=9” then it should response with a dynamically created json file named cities.json which contains the cities which are in state #9?
Thanks in advance!
There are a number of ways to do this – basically, the simplest is to have any standard web page (be it forms, an MVC controller/action/etc…) that acts like any normal webpage would with user input but instead of returning html, it returns XML. (By returns XML, I mean make the contents of the page solely XML and add the appropriate headers)
Your question is too broad to give more details – but simply put, it’s easily done and the client (JavaScript in this case) can’t usually tell the difference.