关于使用ajax我在网上找到了两种解决方法,请看:
方法1:
var xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );
function IDRequest()
{
xmlhttp_request=getXMLRequester();
xmlhttp_request.onreadystatechange = doContents;
xmlhttp_request.open('GET', 'http://www.163.com', true);
xmlhttp_request.send(null);
}
function doContents()
{
}
方法2:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script language="javascript" type="text/javascript">
function showEmployee(firstName, lastName, title)
{
var request = new Sys.Net.WebRequest();
request.set_url('GetEmployee.ashx');
request.set_httpVerb("POST");
request.add_completed(onGetEmployeeComplete);
var requestBody = String.format(
"firstName={0}&lastName={1}&title={2}",
encodeURIComponent(firstName),
encodeURIComponent(lastName),
encodeURIComponent(title));
request.set_body(requestBody);
request.invoke();
}
function onGetEmployeeComplete(response)
{
if (response.get_responseAvailable())
{
var employee = response.get_object();
alert(String.format(
"Hello I'm {0} {1}, my title is '{2}'",
employee.FirstName,
employee.LastName,
employee.Title));
}
}
</script>
问题1:这两种方法哪个更好?大家都常用哪个方法?
问题2:还有没有其它方法?