2010-09-17 79 views
0
jQuery(function ($) { 
    /* fetch elements and stop form event */ 
    $("form.follow-form").submit(function (e) { 
     /* stop event */ 
     e.preventDefault(); 
     /* "on request" */ 
     $(this).find('i').addClass('active'); 
     /* send ajax request */ 
     $.post('recycle.php', { 
      followID: $(this).find('input').val() 
     }, function() { 
      /* find and hide button, create element */ 
      $(e.currentTarget) 
       .find('button').hide() 
       .after('<span class="following"><span></span>Following!</span>'); 
     }); 
    }); 
}); 

的HTML:我的jquery ajax请求没有访问数据库?

<form class="follow-form" method="post" action="recycle.php"> 
    <input name="id" value="$id" type="hidden"> 
     <input name="$tweet" value="$tweet" type="hidden"> 
    <button type="submit" value="Actions" class="btn follow" title="123456"> 
     <i></i><span>recyle</span> 
    </button> 
</form> 

reycle.php:

<?php session_start(); 
include_once ('includes/connect.php'); 

$id = $_POST['id']; 
$tweet =$_POST['tweet']; 


    $registerlistener = mysql_query("INSERT INTO notes (user_id, user_note,recyle_id,dt) VALUES('".$_SESSION['user_id']."','".$tweet."','".$id."',NOW()"); 



?> 

的问题是,它不是访问recycle.php文件,插入HTML表单的信息到数据库!但它正在做整个jQuery动画!我没有看到最新的问题!

+0

什么是“整个jQuery动画”? – elektronikLexikon 2010-09-17 17:02:40

+0

基本上当我点击reycle按钮时,它变成了文字说“回收” – getaway 2010-09-17 17:04:05

+0

该值'=“$ id”'不是'value =“<?php echo $ id?>”',并且与$ tweet相同' – RobertPitt 2010-09-17 17:36:16

回答

0

var_dump()$_POST变量在你的PHP脚本,并检查使用Firebug(Firefox扩展)的响应。这样你就可以看到什么通过。

但我认为你的数据收集存在问题。 这可能会实现:

$.post('recycle.php', { 
    id: $(this).find('input[name=id]').attr('value'), 
    tweet: $(this).find('input[name~=tweet]').attr('value') 
    }, 
    function(response){ 
    //on success code 
    }); 

可以证实这一点要么萤火日志(console.log)或var_dump结果。

0

使用萤火虫控制台或类似的东西,看看是否有任何404或其他错误。如果您没有看到任何404错误,请检查您的php脚本。

+0

ive添加了php scirpt,它不会向数据库添加任何内容 – getaway 2010-09-17 17:11:56

+0

检查PHP脚本中的逻辑和发生了什么。调试工作可以帮助很多。 – 2010-09-17 17:43:30

0

你的语法肯定看起来不错,尝试添加变量回调到签名

+0

对不起,我得到你的意思,我有点新手在这里 – getaway 2010-09-17 17:08:14