簡體   English   中英

麻煩jquery.post()和php curl

[英]having trouble with jquery.post() and php curl

我做了一個腳本,可以在頁面上發表評論。 我使用過PHP curl,它可以工作,但是我需要使用AJAX,這樣才能重新加載頁面。 當我使用jQuery .post() ,響應顯示:

方法不允許使用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;
});

有誰知道什么是錯的?

我已經通過使用$.ajax()而不是.post()修復了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM