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

通过ajax传递价值

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)
     {
     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
     }   } 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:

<script>
$(document).ready(function () {
    $("input#delete-btn").click(function(){
        $.ajax({
            type: "GET",
            url: "1.php",  
            data: {id: 1234 } 

        });
    });
});
</script>

html+php code:

 <?php
 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)