возникли проблемы с jquery.post () и php curl - PullRequest
0 голосов
/ 03 августа 2010

Я сделал скрипт для публикации комментариев на странице. Я использовал 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;
});

Кто-нибудь знает, что не так?

1 Ответ

2 голосов
/ 03 августа 2010

Я исправил это, используя $.ajax() вместо .post().

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...