帮助与结构"单页"阿贾克斯网站 [英] Help with structure for "single-page" Ajax website
问题描述
我知道规则,这是不是真的可以回答的问题,但我真的需要帮助与此有关。
I know about the rules and this is not really a question that can be answered, but I really need help with this.
我在做一个网站,有一个JavaScript的音乐播放器,每次不能被中断的页面的用户更改。因此,网站必须是一种单一的页面,加载的ASPX文件使用AJAX。
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?
如果我使用的播放器一个母版和分离的aspx文件,我就可以加载这些文件与阿贾克斯?
If I use a Masterpage with the player and separated aspx files, will I be able to load these files with ajax?
任何帮助,结构或AJAX样本将AP preciated。
Any help with structure or an ajax sample would be appreciated.
推荐答案
我会建议你利用 MVC框架一>这一点。然后,您可以方便地通过客户端AJAX调用呼叫控制器的操作方法。这里有一个简单的例子:
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;
}
}
这篇关于帮助与结构&QUOT;单页&QUOT;阿贾克斯网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!