2014-10-28 25 views
-1
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$("a.01").click(function({ 
     $.post("test.php"); 
} 
)) 
}) 
</script> 
<div><a class="01" href='test.php'><img src="../photo/test.jpg" width="100"></a></div> 

我怎麼能說出來,如果點擊img,將日期插入到mysql中。 THX ..我怎麼說呢,如果點擊img,將日期插入到mysql中。

+0

讓它*寬掃*?這是阿賈克斯 – gr3g 2014-10-28 20:54:50

回答

0

這基本上是如何ajax工作。我不知道你想用ajax發送哪些數據到php。
這是件innerHTML

HTML:

<div id="test" onclick="return send();"> 
Click 
</div> 

JS:

function send() { 

var x = document.getElementById("test").innerHTML; 

$.post(
     'insertData.php', 
     { 
      firstname : x 
     }, 

     function(data){ 

      if(data == 'Hello World'){ 
       alert('done'); 
      } 
      else 
      { 
      alert('there was an error'); 
      } 

     }, 

     'text' 
    ); 
     } 

     return false; // keeps on the same page 
}); 

}

PHP

<?php 
//MYSQL REQUEST HERE 

echo 'Hello World'; 

?>