XML 在进行 ajax 调用后不呈现
XML does not render after making an ajax call
我正在尝试进行 ajax 调用,并在服务器上从 table 访问一个字段,我有以下内容:
<PushProperty><Status ID = "1"> Success </Status><ResponseID> b3633c9eeb13498f </ResponseID><ID> 9098 </ID></PushProperty>
我希望此结果以其各自的格式和标签显示,但我无法获取。
在控制器中我有以下内容:
class RequestResponseController extends Controller
{
public function show_data(Request $request){
$rr = RequestResponse::find( $request->id);
$text = $rr->response;
return $text;
}
}
从视图中我称它为 ajax:
function show_request_response (id, type) {
$.ajax ({
url: "/request_responses/show_data",
data: {
"_token": "{{csrf_token ()}}",
"id" : id,
"type": type,
},
method: "POST",
async: false,
success: function (xmlResponse) {
$ ('# exampleModal'). modal ('show');
$ ('# exampleModal .modal-title'). html ("Response XML");
$ ('# exampleModal .modal-body'). html (xmlResponse);
}
});
return false;
}
但在模式中它只显示没有 xml 标签的文本,即:
成功b3633c9eeb13498f9098
但我需要得到:
<PushProperty>
<Status ID="1">Success</Status>
<ResponseID>b3633c9eeb13498f</ResponseID>
<ID>9098</ID>
</PushProperty>
希望对我有帮助谢谢。
您正在使用 jQuery 的 html()
方法,该方法告诉它将输入解析为 HTML。
在 HTML 中 <this>
是一个标签,不会呈现为纯文本。
如果您想告诉 jQuery 将输入呈现为文本而不是 HTML 源代码,请使用 text()
方法。
我正在尝试进行 ajax 调用,并在服务器上从 table 访问一个字段,我有以下内容:
<PushProperty><Status ID = "1"> Success </Status><ResponseID> b3633c9eeb13498f </ResponseID><ID> 9098 </ID></PushProperty>
我希望此结果以其各自的格式和标签显示,但我无法获取。
在控制器中我有以下内容:
class RequestResponseController extends Controller
{
public function show_data(Request $request){
$rr = RequestResponse::find( $request->id);
$text = $rr->response;
return $text;
}
}
从视图中我称它为 ajax:
function show_request_response (id, type) {
$.ajax ({
url: "/request_responses/show_data",
data: {
"_token": "{{csrf_token ()}}",
"id" : id,
"type": type,
},
method: "POST",
async: false,
success: function (xmlResponse) {
$ ('# exampleModal'). modal ('show');
$ ('# exampleModal .modal-title'). html ("Response XML");
$ ('# exampleModal .modal-body'). html (xmlResponse);
}
});
return false;
}
但在模式中它只显示没有 xml 标签的文本,即:
成功b3633c9eeb13498f9098
但我需要得到:
<PushProperty>
<Status ID="1">Success</Status>
<ResponseID>b3633c9eeb13498f</ResponseID>
<ID>9098</ID>
</PushProperty>
希望对我有帮助谢谢。
您正在使用 jQuery 的 html()
方法,该方法告诉它将输入解析为 HTML。
在 HTML 中 <this>
是一个标签,不会呈现为纯文本。
如果您想告诉 jQuery 将输入呈现为文本而不是 HTML 源代码,请使用 text()
方法。