I know about the rules and this is 开发者_StackOverflownot really a question that can be answered, but I really need help with this.
I'm making a website that have a javascript music player that cannot be interrupted every time the user changes between pages. So, the site must be a sort of single page, loading the ASPX files with AJAX.
What structure should I use for this?
If I use a Masterpage with the player and separated aspx files, will I be able to load these files with ajax?
Any help with structure or an ajax sample would be appreciated.
I would suggest you leverage the MVC Framework for this. You can then easily call Controller's Action methods via client-side AJAX calls. Here's a simplified example:
// jQuery AJAX call.
function getContacts() {
$.ajax({
type: 'get',
url: '/Contacts/GetContacts',
dataType: 'json',
success: function (response) {
var contacts = response;
},
error: function (e) {
alert('oops!');
}
});
}
// Server-side.
public class ContactsController : Controller
{
[HttpGet]
public JsonResult GetContacts()
{
JsonResult result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
List<Contacts> contacts = DataAccess.GetContacts();
result.Data = contacts;
return result;
}
}
精彩评论