2016-05-29 15 views
-1

私は単純なコードを持っていますが、動作しません。より複雑な関数を作成したいが、基本的な構造が必要なだけである。Jquery simple Ajax Post PHPが動作しない

HTML

<span class="cleanreport">Delete Record</span> 

Javascriptを:

$(".cleanreport").click(function() { 

var token = "test"; 

$.ajax({ 
data: {"data": token}, 
type: "post", 
url: "clean.php", 
success: function (data) { 
console.log(data); 
$('.test').html(data); 
    } 
    }); 
}); 

PHPのclean.php私が間違っているのは何

$data = $_POST['data']; 
echo $data; 

+0

PHP $ _POSTをテストしましたか?空の場合は$ tempData = file_get_contents( "php:// input")を試してください。 PHPのerror_logを出力するか、出力をダンプしてPHPをテストします。 –

+0

'type:" post "、' ==> 'メソッド:" POST "、 –

+0

私は他のajax呼び出しを私のウェブサイトに投稿しています。 –

答えて

0

これはあなたのために働く必要があります。

var token = "test"; 
$.ajax({ 
    type: 'POST', 
    url: "clean.php", 
    data: {id: token}, 
    dataType: "json", 
    success: function(response) { 
     // some debug could be here 
    }, 
    error: function(a,b,c) { 
     // some debug could be here 
    } 
}); 

ない場合は、console.log()を使用してsuccesserrorパラメータをデバッグしてください。

jquery documentation設定typemethodのエイリアスです。この場合は問題ありません。

+0

申し訳ありませんが、まだ動作していません。私はconsole.logで試しましたが、何も表示されず、error.logのエラーも表示されませんでした。 –

+0

Okを修正しました。$(function(){....})の中にajax関数を追加するだけです。ありがとう –

0
$(".cleanreport").click(function() { 
    var token = "test"; 
    $.post('clean.php", 
    { 
     data: token 
    }, 
    function (data,status) { 
     //console.log(data); 
     $('.test').html(data); 
    }); 
}); 
+0

申し訳ありませんが、これは動作しません。 –

関連する問題