使用Ajax更改网页内容 [英] Changing web page content using Ajax

查看:73
本文介绍了使用Ajax更改网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用Javascript AJAX动态更新网页内容的最佳方法.

I'm looking for the best way to dynamically update a web page content using Javascript AJAX.

我的第一个想法是在各种文件中存储各种 div 布局,每个布局描述一个不同的页面,例如:

My first thought is to store various div layouts each describing a different page in various files, for example:

BasicDiv.div:

BasicDiv.div:

<div>
    <p>Some Text</p>
    <button> A Button </button>
</div>

-然后在主网页内创建一个空的 div ,将更新其内容,然后创建一个 XMLHttpRequest 并更新 div.innerHtml 以及从所需文件中加载的数据.

-Then create an empty div ,which content will be updated, inside the main webpage, then I make a XMLHttpRequest and update the div.innerHtml with the data loaded from the required file.

这是使用AJAX的好方法还是您有更好的建议?

Is this a good way to use AJAX or do you have a better suggestion?

推荐答案

jquery ajax

jquery ajax

$.ajax({
  url: "test.php",
  type: "POST",
  data : { var:'val1',var2:'val2' }
}).done(function() { 
  $("<div>").innerHTML("done");
});

这篇关于使用Ajax更改网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆