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. But when i use jquery post the response says: method not allowed use post or get. this the codes:
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);
and this is the jquery.post
$("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 whats wrong?