するvar dataString = 'コンテンツ=' +のTextContentに次のように私は私の$ _POSTを持っているImが
<script type="text/javascript">
$(function() {
// call the submit button ref: name
$(".submit_button").click(function() {
declare textcontent
var textcontent = $("#content").val();
//dataString = 'content' globel var
var dataString = 'content='+ textcontent;
declare info
var info = $('#name').val();
// option no text inputted
if(textcontent=='')
{
// show message if no text
alert("Enter some text..");
$("#content").focus();
}
else
{
//display text animation loading
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="load">Loading..</span>');
//var info equals the string
var info = $('#content').val();
//start ajax call
$.ajax({
type: "POST",
//path to my action.php
url: "actions/action_comment.php",
//Need to undestand how to correctly format these lines so
//they are both succesful when submitted to my action_comment.php
$me is declared (not-shown here it holds integer)
data: {name: info, me: '<?php echo $me; ?>'},
// pass the string from textarea to $_POST
data: dataString ,
// I can get one or the other to work but not both
cache: true,
// feed the success my data
success: function(html){
$("#show").after(html);
document.getElementById('content').value='';
$("#flash").hide();
$("#content").focus();
}
});
}
return false;
});
});
</script>
をやって何を概観与えるために完全なコードです。
$.ajax({
type: "POST",
url: "actions/action_comment.php",
data: {name: info, me: '<?php echo $me; ?>',txt_data: dataString},
....
});
同じajaxリクエストでデータ属性を複数回使用することはできません。 PHPファイル内では、$ _POST ['txt_data']のようにアクセスして、テキストエリアのコンテンツを取得し、他のパラメータと同じ方法で取得できます。
一度データ属性を定義し、上記のようにすべてのデータを渡します。あなたが全体のフォームデータを転記する場合
あなたはこのよう
var form = $('#my_form');
$.ajax({
type: "POST",
url: form.attr('action'),
data: form.serialize(),
..
..
});
を使用することができ、これはJavaScriptファイルやPHPファイルのですか? JavaScriptファイルの場合は、その中でPHPコードを使用することはできません。また、コードを本当にインデントする必要があります。これは読みにくいです。 – Novocaine
JSとのphp、私は私のコードをインデントします –
$ meの値は何ですか?(<?php echo $ me;?>) –