2010-08-03 106 views
0

我做了一个脚本在页面上发表评论。我已经使用PHP卷曲,它的工作原理,但我需要使用AJAX,因此页面不会重新加载。当我使用jQuery .post()的回应说:jquery.post()和php卷曲有问题

方法不允许使用post或get。

这是我的代码:

include("userinfo.php"); 
if ($_POST['action'] === 'postcomment'){ 
    $imageid = $_POST['imageid']; 
    $user = $_POST['username']; 
    $text = $_POST['text']; 
} 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:", "Api-Key: ".$apikey)); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_URL, "https://api.myphotodiary.com/users/".$user."/images /".$imageid."/comments.json"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array("text" => $text)); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POST, true); 
$response = curl_exec($ch); 
print_r($response); 

这是jQuery的:

$("form.imagecommentform").live("submit",function(e){ 
    $text = $(this).find(".text"); 
    $username = $(this).find(".username"); 
    $imageid = $(this).find(".imageid"); 
    $.post("inc/imagecomment.php",{ 
     immageid: $imageid.val(), 
     username: $username.val(), 
     text: $text.val() 
     action: "postcomment" 
    }, function(html) { 
     $(this).find($(".msg")).empty(); 
     $(this).find($(".msg")).html(html); 
    }, "json"); 
    return false; 
}); 

有谁知道什么是错?

回答

2

我已经使用$.ajax()而不是.post()修复了它。