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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办