如何显示JQuery ajax请求返回的表?

时间:2022-08-25 18:09:15

I am developing in CakePHP.

我正在开发CakePHP。

Here is the ajax:

这是ajax:

$.ajax
({
     url: 'http://domnain/subdomain/controller/add/',
     accepts: 'text',
     context: document.body,
     type: 'POST',
     data: account_data,
     dataType: 'html',
     success: function( data, textStatus, jqXHR )
     {
          .
          .
          .

          $('#account_post_message').html( data );

          .
          .
          .

The target controller creates the following:

目标控制器创建以下内容:

$return_html = '<table><tr><td>American Express</td><td>5678</td><td>10/13</td></tr></table>';

which is echoed echo $return_html; to the ajax and is places in the "account_post_message" <div>.

这是回声echo $ return_html;到ajax并且是“account_post_message”

中的位置。

Unfortunately, the text string appears as a string.

不幸的是,文本字符串显示为字符串。

How can I make the table appear as a table?

如何使表格显示为表格?

1 个解决方案

#1


0  

Well first of all the returned value is a string, not an HTML markup string; its just text. You can change the return value to be HTML markup or parse the returned string in your JavaScript to produce HTML markup to be added to the "account_post_message"

首先返回的值是一个字符串,而不是HTML标记字符串;它的正文。您可以将返回值更改为HTML标记,或者在JavaScript中解析返回的字符串以生成要添加到“account_post_message”的HTML标记

For example:

例如:

$return_html = 'table table_row table_data American Express end_table_data table_data 5678 end_table_data table_data 10/13 end_table_data end_table_row end_table';

Should be something like:

应该是这样的:

$return_html = '<table><tr><td>American Express</td><td>5678</td><td>10/13</td></tr></table>';

Like I said you can make the controller return this HTML or replace the string tokens in your response with the corresponding HTML tags

就像我说过你可以让控制器返回这个HTML或者用相应的HTML标签替换你的响应中的字符串标记

#1


0  

Well first of all the returned value is a string, not an HTML markup string; its just text. You can change the return value to be HTML markup or parse the returned string in your JavaScript to produce HTML markup to be added to the "account_post_message"

首先返回的值是一个字符串,而不是HTML标记字符串;它的正文。您可以将返回值更改为HTML标记,或者在JavaScript中解析返回的字符串以生成要添加到“account_post_message”的HTML标记

For example:

例如:

$return_html = 'table table_row table_data American Express end_table_data table_data 5678 end_table_data table_data 10/13 end_table_data end_table_row end_table';

Should be something like:

应该是这样的:

$return_html = '<table><tr><td>American Express</td><td>5678</td><td>10/13</td></tr></table>';

Like I said you can make the controller return this HTML or replace the string tokens in your response with the corresponding HTML tags

就像我说过你可以让控制器返回这个HTML或者用相应的HTML标签替换你的响应中的字符串标记