我想通过ajax将从jquery获取的数据检索到php。
启动模态窗口的代码
<a href='javascript:void(0):' data-id={$row['customer_id']} class='btn small bg-blue-alt tooltip-button modal-customeredit' data-placement='top' title='Edit'><i class='glyph-icon icon-edit' ></i>
这里从主页面获取id。并打开一个模式弹出窗口。 模态脚本如下。
$( ".modal-customeredit" ).click(function() {
var myGroupId = $(this).attr('data-id'); // data-id
data = {'id':myGroupId };
$.ajax({
type: "POST",
url: "left.inc.php",
data: data, // data retrieve on server-side ($_POST['id'])
success:function(response){
$( "#modal-customeredit" ).dialog({
modal: true,
minWidth: 700,
minHeight: 200,
dialogClass: "modal-dialog",
show: "fadeIn"
});
alert('done');
alert(response); //do the rest of operations.
}
});
my form code is for modal:
<!-- Customer Edit -->
<div class="hide" id="modal-customeredit" title="Edit Customer Info">
<div class="pad10A">
<h3>Update Customer Info</h3>
<p class="font-gray-dark"> Fides Admin uses colors & styles from both the default theme color schemes and the included core color helpers. </p>
<div class="divider"></div>
<form id="customer-edit" action="" class="col-md-12 center-margin" method="">
<div class="form-row">
<div class="form-label col-md-3">
<label for="name">
Name:
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="name" name="name" placeholder="Name" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="details">
Details :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="details" placeholder="Details" name="details" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="domain">
Domain :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="domain" placeholder="Domain" name="domain" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="vertical">
Vertical :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="vertical" placeholder="Vertical" name="vertical" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="form-row">
<div class="form-label col-md-3">
<label for="taxanomy">
Taxanomy :
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="taxanomy" placeholder="Taxanomy" name="taxanomy" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="divider"></div>
<div class="form-row">
<div class="form-input col-md-8 col-md-offset-3">
<a href="javascript:;" class="btn medium primary-bg radius-all-4" id="customer-edit-valid" onclick="javascript:$('#customer-edit').parsley( 'validate' );" title="Validate!"><span class="button-content">Submit</span></a>
</div>
</div>
</form>
</div>
</div>
<?php } elseif ($pfile=="customer-screen.php") { ?>
我面临的问题是我从ajax得到了回应。它显示了我想要的确切ID。 但是当我在php中尝试
时<?php $id=$_POST['id'];
echo $id; ?>
我无法回复php文件中的id.But ajax显示在response.Hope我正在传达问题。如果你帮助它将非常感激。如果你对我的问题有疑问。请评论让我expalin。
答案 0 :(得分:-1)
您发布的数据是JSON格式,而不是网址格式。数据应为'id ='+ myGroupId。