我有一個JSON從PHO功能(如下所示)返回的數據:將JSON轉換成模
[{"id":"15","activity_type":"call","activity_title":"Call to check "}]
這裏發起請求(actvitiy.js)腳本(編輯)
$(document).on("click", ".view_contact_activity", function() {
var this_activity_id = $(this).closest('.feeds').find('#this_activity_id').val();
$('#view-contact-activity').modal('show');
$.ajax({
url: '../includes/functions/contact-functions.php',
data: {view_activity_id:this_activity_id},
dataType:'json',
Success: function(response){
$('#activity_id').val(response[0].id);
$('#activity_type').val(response[0].activity_type);
}
});
});
,我需要的數值,顯示模式:
<div class="modal fade" id="view-contact-activity" tabindex="-1" role="basic" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="portlet-body form">
<form class="form-horizontal" role="form" id="view-contact-activity-form" method="post">
<div class="form-group">
<label class="col-sm-3 control-label col-lg-3"> Activity Title</label>
<input type="text" name="activity_id" id="activity_id" value="">
<label class="col-sm-3 control-label col-lg-3"> Activity Type</label>
<input type="text" name="activity_type" id="activity_type" value="">
<div class="modal-footer">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" name="create-new-account" class="btn btn-danger" id="edit">Edit Activity</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
模態表演,但沒有數據傳遞給模式。任何想法我可能在這裏做錯了。
編輯:返回JSON
function view_activity(){
global $connection;
$activity_id = $_POST['view_activity_id'];
$get = "SELECT * FROM contact_activities WHERE activity_id = '$activity_id' "
or die("Error: ".mysqli_error($connection));
$query = mysqli_query($connection, $get);
$activitiy_field = array();
while ($activity_array = mysqli_fetch_array($query)){
$activity = array(
'id' => $activity_array['activity_id'],
'activity_type' => $activity_array['activity_type'],
'activity_title'=>$activity_array['activity_title'],
'activity_details'=>$activity_array['activity_details'],
'activity_status'=>$activity_array['activity_status'],
'activity_details'=>$activity_array['activity_details'],
'activity_details'=>$activity_array['activity_details'],
);
$activitiy_field[] = $activity;
}
echo json_encode($activitiy_field);
}
if (isset($_POST['view_activity_id'])) {
view_activity();
}
添加PHP函數謝謝。
我覺得它吸引的時候,你調用'.modal(「秀」)',並將其複製到一個單獨的DIV的HTML,所以你的HTML的變化沒有任何效果,因爲它們發生後的模式已經打開。嘗試將'$('#view-contact-activity')。modal('show');'移到ajax成功回調的底部。 – 2015-02-08 04:47:18
@MattBrowne我試過了,沒有改變。我關閉ajax請求後放置。 – EDarrien 2015-02-08 04:56:40