2010-08-03 107 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()修復了它。