开发者

having trouble with jquery.post() and php curl

开发者 https://www.devze.com 2023-01-10 11:26 出处:网络
I made a script to post comments on a page. I have used PHP curl and it works but I need to use AJAX so the page doesn\'t reload. When i use jQuery .post() the response says:

I made a script to post comments on a page. I have used PHP curl and it works but I need to use AJAX so the page doesn't reload. When i use jQuery .post() the response says:

method not allowed use post or get.

This is my code:

include("userinfo.php");
if ($_POST['action'] ==开发者_JS百科= '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);

And this is the 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;
});

Does anyone know what is wrong?


I have fixed it by using $.ajax() instead of .post().

0

精彩评论

暂无评论...
验证码 换一张
取 消