3 回答

TA貢獻1864條經驗 獲得超6個贊
您可以像這樣更改 PHP 內部的代碼
<?php
$queryResult = '<div id="id-query-result">hello</div>';
echo json_encode(['html' => $queryResult]);
然后,改變你的ajax調用
jQuery.ajax({
type: "GET",
url: "the_file_to_call.php",
data: {userid: group_id_tb},
dataType: 'json',
success: function(data) {
var the_returned_string = data.html;
alert(the_returned_string);
}
});

TA貢獻1786條經驗 獲得超13個贊
$.ajax({
type: "POST",
url: "the_file_to_call.php",
data: {userid: group_id_tb},
success: function(data) {
$('body').append(data);
var text = $('#id-query-result').text();
alert(text);
$('#id-query-result').remove()
}
});
為什么不直接附加 php 文件的 HTML 響應,然后獲取相應的文本。之后您可以將其刪除。

TA貢獻1801條經驗 獲得超16個贊
有兩個更改需要完成:
type
由于您直接調用 PHP 文件,因此將其更改為“GET”。刪除 success 函數中包裝的 jQuery 方法并添加
.html
為屬性
jQuery.ajax({
type: "GET",
url: "the_file_to_call.php",
data: {userid: group_id_tb},
success: function(data) {
var the_returned_string = data.html
alert(the_returned_string)
}
});
添加回答
舉報