weixin_33722405 2015-02-02 07:32 采纳率: 0%
浏览 34


I am new to ajax and i don't have much idea about ajax. I am trying to pass the value from url using ajax but i am not being able to do so. I have done few search on google and found some ajax function code and i tried to implement on my code but one code is not working and another code is giving error. I have left both code below:-

error:-1 ajax code

  <script> function loadXMLDoc(loadXMLDoc) { var xmlhttp; if

(window.XMLHttpRequest)   {
 Safari   xmlhttp=new XMLHttpRequest();   } else   {
 IE5   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   }
 xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readyState==4
 && xmlhttp.status==200)
     }   } xmlhttp.open("GET","1.php?check=<?php if(isset($_GET['check'])){echo $_GET['check'];}else{echo "i am
 mad";} ?>&name="+loadXMLDoc,true); xmlhttp.send(); } </script>

html+php code

<?php if(isset($_GET['check'])){echo $_GET['check'];} ?> <?php
 if(isset($_GET['name'])){echo $_GET['name'];} ?> <div id="myDiv"><h2
 style="display:none;">Let AJAX change this text</h2></div> <input
 type="text" onChange="loadXMLDoc(this.value)">

error:- 2 ajax code:

$(document).ready(function () {
            type: "GET",
            url: "1.php",  
            data: {id: 1234 } 


html+php code:

 if(isset($_GET['id'])){echo $_GET['id'];} ?> `<div id="myDiv"><h2 style="display:none;">Let AJAX change this text</h2></div>`

 <input type="text" onChange="loadXMLDoc(this.value)">

I just want to pass the value from url to the same page using ajax but i am not being able to do so. Hope i will get help over here. Thank You in advance.

  • 写回答

2条回答 默认 最新

  • ~Onlooker 2015-02-02 07:37

    well, the data is passed as the body of the request. Set your Content-type in your header request to application/x-www-form-urlencoded so that PHP can $_GET[] it.




  • ¥20 家用射频美容仪技术规格
  • ¥25 matlab数值溢出该怎么解决?
  • ¥15 大家帮我看看为什么错了
  • ¥15 unity互动琴弦抖动效果
  • ¥15 做了个的二极管反向饱和电流测量电路,但是测试达不到效果
  • ¥15 nginx无证书访问https失败
  • ¥15 树莓派启动AP热点传入数据
  • ¥15 multisim中关于74ls192n和DSWPK开关的问题(相关搜索:计数器)
  • ¥15 在误装Windows server2019 后如何利用Windows.old恢复?
  • ¥20 代码实现状态连接包过滤防火墙的设计与实现