Ajax通过单击href加载.php

时间:2014-10-03 10:45:19

标签: php ajax string

我想要一个简单的方法,当我点击它时,它会从文件file.php中加载内容。 我还需要Ajax将字符串发送到file.php

这是我的file.php

session_start();

include("../database.php");

if (isset($_GET['id'])) {

$to = $_GET['to'];

mysql_query("UPDATE `flashchat` SET `open` = '1' WHERE `to` = '$to' AND `from` = '$_SESSION[id]'");

}

PHP字符串

$chatinfo[id];

谢谢!

2 个答案:

答案 0 :(得分:1)

$(function(){
    $('#link').click(function(){
        var to = <?php echo $chatinfo['to']; ?>;
        $.ajax({
            type: 'GET',
            url: 'lukk.php',
            data: 'id='+to+,
            sucess: function() {
                $('#sucess').html(data);
            }
        });
        return false;
    });
});

答案 1 :(得分:1)

<a id="link" href="#">Click on me to get the contents of the file.php</a>

<div id="result">Result form file.php</div>

<script>
  $("#link").click(function(){
    $.ajax({
      type: "GET",
      url: "file.php",
      data: { id: 123, to: 456 }
    })
    .done(function( html ) {
      $("#result").html( html );
    });
  })
</script>