Why my ajax failed?

Hi guys!

I am writing a program in ajax and php,
my ajax can pass the data to my php, and my php also can receive and save the data to my DB.

But, my problem is the ‘error: function ()’ of my ajax always be fried.
In other words, I can’t do something to send a response to my frontend after my ajax has been successfully completed,
Could you please tell me why?

My ajax:

function SetAdvisePrice(){
	if ($("#AdvisePrice").find("option:selected").val()) {
			url: WebsitePath + '/settings',
			data: {
				AdvisePrice: $("#AdvisePrice").find("option:selected").val()
			type: 'POST',
			dataType: 'json',
			success: function (Result) {
			if (Result.Status == 1) {
			//do something
			else {
		error: function () {
                        //always stuck in here

My php:

$AdvisePrice = intval(Request('Post', 'AdvisePrice'));
$MerchandiseResult = $AdvisePrice;
if (empty($MerchandiseResult)) {
$MerchandiseResultMessage = '商品信息没有被修改';
else {
		try {
		$DB->query('UPDATE ' . PREFIX . 'users SET AdvisePrice = :AdvisePrice WHERE ID = :ID',
		"AdvisePrice" => $MerchandiseResult,
		"ID" => $CurUserInfo['ID']
		} catch (Exception $ex) {
			return false;
		echo json_encode(array('Status'=>'1'));
		$MerchandiseResultMessage = '商品信息设置成功';

I don’t know is it safty, but I did this:

error: function (jqXHR, exception) {
		 if(jqXHR.statusText== 'OK'){
			 alert('商品设置成功。' + '您目前的咨询费是' + AdvisePrice + '元半小时。');

It seems to resolved my problem temporarily.

1 Like