イベントのあるフォームがありonkeyup
ます。php スクリプトに変数を送信し、結果を div に表示しようとしています。
このフォーラムのおかげで、テスト機能が半分になりました。
jQuery.post(the_ajax_script.ajaxurl,
続行すると: 1) jQuery("#theForm").serialize(),
"Hello World" という応答テキストが表示されます。変数を渡そうとすると: 2){ name: "p" },
取得: -1
JavaScript
function submit_me(){
jQuery.post(
the_ajax_script.ajaxurl,
{ name: "p" },
function(response_from_the_action_function){
jQuery("#txtHint").html(response_from_the_action_function);
}
);
}
PHP
<?php
function the_action_function(){
$name = $_POST['name'];
echo "Hello World, " . $name;
die();
}
?>
形
<form id="theForm">
<input type="text" name="user">
<input name="action" type="hidden" value="the_ajax_hook">
<input id="submit_button" value = "Click This" type="button" onkeyup="submit_me()">
<form>
私は実際にonkeyup="submit_me(this.value, 0)"
、admin-ajax.php ファイルを介して WordPress でこれを実行したいと考えています。
これのどこに問題があるのですか?
編集
どうやら私はデータにアクションを追加しなければならなかった
{ action:'the_ajax_hook', name:"p" }
例を次のように見たので、jQueryではなくWPの要件だと思います。
$.post("test.php", { name: "John", time: "2pm" }
どこにでも。