ajax可以有多个返回函数吗,如何将多个值返回给jQuery.Ajax成功函数

2023-05-16

大家都已经知道,帮助编程的最好方法就是向他们展示实例。所以这是我的一部分。

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...

希望它会帮助你.. :)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ajax可以有多个返回函数吗,如何将多个值返回给jQuery.Ajax成功函数 的相关文章

随机推荐