日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

ajax php 返回数组并父子给变量,将字符串变量从PHP发送回数组变量的ajax ...?

發布時間:2025/3/15 php 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax php 返回数组并父子给变量,将字符串变量从PHP发送回数组变量的ajax ...? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想將一條消息保存在PHP變量中,并用已返回的其他數組變量發回。例如,我在PHP代碼中發生了一些錯誤檢查,并想要一個字符串變量,并將特定的消息發送回我的javascript中使用。將字符串變量從PHP發送回數組變量的ajax ...?

這里是PHP:

include('config-searchres.php');

$term = $_POST['resid'];

$sql = mysql_query("SELECT * FROM ap_form_8 WHERE id = '$term'"); //select first name (element_1_1) from form #8

if ($row = mysql_fetch_array($sql)){ //if reservation number exists

if ($row['element_11'] != 'Cancelled'){ //if reservation has not already been cancelled

if (strtotime($row['element_3']) >= strtotime(date("Y-m-d"))){ //if reservation has not already passed date

echo json_encode($row);

}

else //Reservation already passed (old reservation)

{

echo 'passed';

}

}

else //Reservation already cancelled

{

echo 'cancelled';

}

}

else //Reservation not found

{

echo 'not found';

}

mysql_close();

?>

正如你可以看到,有3級不同的消息,“合格”,“取消”和“未找到” ......如果這些條件之一存在,我想把這個字符串發回給我的JavaScript,所以我可以在DIV中顯示它。不過,我也想發送$ row數據。

我的javascript:

$(document).ready(function(){

resetForms('reservation');

$('#form-reservation').submit(function(event){

event.preventDefault(); //the page will no longer refresh on form submit.

var resCheck = $(this).find('input[class="reservationid"]').val(); //now we have the reservation ID, let's perform our check.

$.ajax({

url: 'inc/searchres.php',

type: 'POST',

data: 'resid='+resCheck,

success: function(data){ //data is all the info being returned from the php file

$('#reservation-id').val(resCheck); //add read ID back into text box

var jsonData = $.parseJSON(data); //parse returned JSON data so we can use it like data.name, data.whatever

//****I wanted the line just below this to display the appropriate message sent back from the PHP****

$("#res-message").html('Reservation ID Located, Information is displayed below');

$('#json-reservation').populate({personal_first_name:jsonData['element_1_1'],personal_last_name:jsonData['element_1_2'],personal_phone_1:jsonData['element_7'],personal_email:jsonData['element_2'],reservation_status:jsonData['ADD THIS CELL'], reservation_id:jsonData['id'], reservation_date:jsonData['element_3'],reservation_time:jsonData['element_4'],reservation_party:jsonData['element_5'],reservation_special_request:jsonData['element_6'],reservation_using_coupon:jsonData['element_9'],reservation_coupon_code:jsonData['element_10'],reservation_status:jsonData['element_11']});

$("#res-cancel-message").html('');

},

error: function(){

$("#res-message").html('There was an error with your request');

$("#res-cancel-message").html('');

}

});

});

});

我打上,我填充在這個時候一個靜態的消息DIV星號,這是我會填充從PHP消息的線。有任何想法嗎?

2012-04-26

tmparisi

總結

以上是生活随笔為你收集整理的ajax php 返回数组并父子给变量,将字符串变量从PHP发送回数组变量的ajax ...?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。