插件83:获得Ajax请求

<html><head><title>AJAX GET Example</title>
</head><body><center />
<h1>Loading a page in-between <font face='Courier New'><div>…</div></font> tags</h1>
<div id='info'>The contents of this DIV will be replaced</div>

<script type="text/JavaScript">

PIPHP_JS_GetAjaxRequest('ajaxget.php',
   'url=http://amazon.com/mobile',
   document.getElementById('info'))

function PIPHP_JS_GetAjaxRequest(url, params, target)
{
   nocache = "&nocache=" + Math.random() * 1000000
   request = new PIPHP_JS_AjaxRequest()
   
   request.onreadystatechange = function()
   {
      if (this.readyState == 4)
         if (this.status == 200)
            if (this.responseText != null)
               target.innerHTML = this.responseText
// You can remove these two alerts after debugging
            else alert("Ajax error: No data received")
         else alert( "Ajax error: " + this.statusText)
   }

   request.open("GET", url + "?" + params + nocache, true)
   request.send(null)
}

function PIPHP_JS_AjaxRequest()
{
   try
   {
      var request = new XMLHttpRequest()
   }
   catch(e1)
   {
      try
      {
         request = new ActiveXObject("Msxml2.XMLHTTP")
      }
      catch(e2)
      {
         try
         {
            request = new ActiveXObject("Microsoft.XMLHTTP")
         }
         catch(e3)
         {
            request = false
         }
      }
   }
   return request
}
</script>

ajaxget.php:

<?php // ajaxget.php

if (isset($_GET['url']))
   echo file_get_contents($_GET['url']);

?>

插件说明:

插件83接受一个网页的URL地址和传递个网页的参数,以及一个用来保存结果的文档对象模型(DOM)。他不返回任何参数,但是如果操作成功,文档对象模型将保持从Web服务器返回的结果。如果操作失败,则出现一个有利于调试的警告窗口。在生产型网站上,我们可能希望禁用这种调试。他需要以下参数:

1.URL:调用Web页面或程序。

2.params:GET参数,用"&"把各参数分开,如var1=value1&var2=value2。

3. target: DOM元素,用来保存调用返回的结果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值