我只想使用Ajax与POST共享我的详细信息到另一个php文件,在我的代码中,post值未初始化为共享,
这是我的代码:
<?php
include('database_connection.php');
if(isset($_POST["action"]))
{
// some logic
// some logic
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= '
<div class="col-sm-3 col-lg-4 col-md-3">
<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
</audio>
<p align="center"><strong> '. $row['voice_name'] .'</strong></p>
<p style="font-size: 12px;">
Voice Id : '. $row['voice_id'].' <br />
Voice Name : '. $row['voice_name'].' <br />
Gender : '. $row['voice_gender'].' <br />
Genres : '. $row['voice_genres'].' <br />
Voice Modulation : '. $row['voice_voice_modulation'].' <br />
Languages : '. $row['voice_languages'].' <br />
Jingle Moods : '. $row['voice_jingle_moods'].' <br />
Ivr : '. $row['voice_ivr'].' <br /> </p>
<button type="button" class="btn btn-primary" style="padding: 5px 83px 5px 83px;
"data-voice-id="'.$row["voice_id"].'
" data-voice-name="'.$row["voice_name"].'
"data-voice-id="'.$row["voice_gender"].'">Add to Playlist</button>
</div>
</div>
';
}
}
else
{
$output = '<h3>No Data Found</h3>';
}
echo $output;
}
?>
<script>
$('.btn').on('click',function() {
var voice_id = $(this).data("voice_id");
var voice_name = $(this).data("voice_name");
var voice_gender = $(this).data("voice_gender");
$.ajax({
method : "POST",
url : "manage_cart.php",
datatype : "text",
data :
{
voice_id: voice_id, voice_name: voice_name, voice_gender: voice_gender
},
success: function(data)
{
// console.log(data);
console.log('success',data);
}
});
});
</script>
我想将voice_id,voice_name,voice_gender共享给manage_cart.php, 我的manage_cart.php文件,
<?php
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$voice_id = '';
$voice_name = '';
$voice_gender = '';
if(isset($_POST['voice_id']) && isset($_POST['voice_name']) && isset($_POST['voice_gender']) )
{
$voice_id = $_POST['voice_id'];
$voice_name = $_POST['voice_name'];
$voice_name = $_POST['voice_gender'];
}
echo $voice_id ."&". $voice_name ."&". $voice_gender;
?>
这里我的帖子值未传递到manage_cart.php。
我该如何解决这个问题?
答案 0 :(得分:0)
您的按钮属性没有let matchedTimesheet = _.find<TimesheetModel>(this.getAllTimesheets() ,
(timesheet) => travelToDate
&& timesheet.startOfWork.isSame(travelToDate.startDate.value, 'days')
); ```
here in the above code it is expecting an array but not Observable., I can do it by subscribing here also , but if the function returns an array instead of observable, then i need to change everywhere
。有重复的data-voice-gender
,并且使用与data-voice-id
类似的变量样式,但是在javascript中,您使用的是data-voice-id