php从javascript抓取数据

时间:2010-01-25 05:22:56

标签: php javascript

显然我尝试将数据保存到mysql中,但它没有用..任何人都有帮助吗?

create_users.php

<form method="post" action="checkAvailability.php">
 <script>
    var macs = { 
    getMacAddress : function() 
    { 
        document.macaddressapplet.setSep( "-" ); 
        return (document.macaddressapplet.getMacAddress()); 
    }}jQuery(document).ready(function(){ 
        var mac = macs.getMacAddress();  
        $.get('/checkAvailability.php?mac=' + mac, function() { alert('yeah done'); }) 
    }); 
</script>  



<script type="text/javascript">
  document.write(macs.getMacAddress());
</script>
    </form>

checkAvailability.php

$dbhost = 'localhost';
$dbuser = 'root';
$dbname = 'registration';
mysql_connect($dbhost, $dbuser) or die("Could not connect database");
mysql_select_db($dbname);
$mac = $_GET['mac'];
$mac = mysql_real_escape_string($mac);
$sql = "INSERT INTO test(mac) VALUES ('$mac')";
mysql_query($sql);

1 个答案:

答案 0 :(得分:4)

您在$ .get()方法中调用“create_users.php”,而应该调用“checkAvailability.php”..

并尝试以客户端形式:

var macs = {
getMacAddress : function()
{
    document.macaddressapplet.setSep( "-" );
    return (document.macaddressapplet.getMacAddress());
}}jQuery(document).ready(function(){
    var mac = macs.getMacAddress(); 
    $.get('/checkAvailability.php?mac=' + mac, function() { alert('yeah done'); })
});