weixin_33709590 2018-04-12 02:59 采纳率: 0%
浏览 45

鼠标悬停时写入MySQL

After months of testing, I'm not succeeding to create a script that writes a logtext to the MySQL when a div gets a mouseover.

I think I have to use $.ajax, the only problem is, is that ajax (still) is the language which I'm not very good at.

One of the 100 things i've tried:

<?
echo "<div id='div0' rel=".$someid.">Some dynamic text</div>";
?>

<script>
           $('.div0').mouseover(function() {
           $('#result').load('../../../system/molog.php?cid='+$(this).attr('rel');
           });
</script>

Who can help?

  • 写回答

1条回答 默认 最新

  • weixin_33709364 2018-04-12 03:19
    关注

    Ok, there's a much better way to do this, but since I'm on a phone that's dying and you have been waiting a year...

    var info = $("#div0").html();
    // if Js in a php file you can do var info = <?php echo $logtext ?>; To bring it to JS 
    $.get("phpfilehere.php", {info:info}, function(data){
    alert(data);
    });
    

    The mouseover function...

    $("#div0").on("mouseover", function(){ 
    // my JS code above goes here
     });
    

    PHP file:

    if(isset($_GET['info'])){
    $log = $_GET['info']; 
    // Put ur stuff here, make sure u only echo when u want ur php script to stop and be sent back to Ajax function as data var.
    // insert $log  
    echo "test";
    } else {
    echo "no get info supplied": 
    }
    

    And here is a tool I made to teach people how to write prepared statements for SQL queries :) if you need it...

    http://wbr.bz/QueryPro/index.php?query_type=prepared_insert

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改