大家都已经知道,帮助编程的最好方法就是向他们展示实例。所以这是我的一部分。
PHP文件和响应
require_once('../../../wp-load.php');
$cs_confID = $_POST['cs_confID'];
$cs_date = $_POST['cs_date'];
$cs_obj = get_conf_id_for_insert($cs_date, $cs_confID);
$json_cs = array();
if(count($cs_obj) == 1)
{
$json_cs = array('cs_id'=>$cs_obj[0]->cs_id,'cs_date'=>$cs_obj[0]->cs_date); //Make array of files
echo json_encode($json_cs); //Encode json
}
else
{
echo '
Status:Error. Please contact our support for further help!
';}
?>
HTML和jQuery
$.ajax({ url: '../wp-content/themes/rirads-2012-child-theme/insert_conference_schedules.php',
data: {cs_date:$("#c_date").val(),cs_confID: $("#conf").val()},
beforeSend: function(){ $("#loaderAjax").show(); },
type: 'post',
success: function(output)
{
$("#loaderAjax").hide();
var obj = jQuery.parseJSON(output); //decode JSON response
$("#cs_id").val(obj.cs_id); //Fill the value of current cs_id into input field cs_id
$("#cs_date").val(obj.cs_date); //Fill the value of current cs_date into input field cs_date
//code goes on...
希望它会帮助你.. :)