When i submit a FORM on my page, my "response text" returns the HTML of the entire page and not only the FORM that submitted. This is normal?
当我在我的页面上提交FORM时,我的“响应文本”将返回整个页面的HTML,而不仅仅是提交的FORM。这个是正常的?
1 个解决方案
#1
responseText is XHR speak for "What the server responds to the request with, excluding the HTTP headers".
responseText是XHR代表“服务器响应请求的内容,不包括HTTP头”。
It is perfectly normal for it to include a complete HTML document if you access a resource designed to respond to a regular form submission.
如果您访问旨在响应常规表单提交的资源,则包含完整的HTML文档是完全正常的。
It sounds like you need to be smarter about what the server responds with.
听起来你需要更聪明地了解服务器的响应。
This simple example (written in Perl, see the link for more context) checks a query string parameter to decide if it should place the data it has fetched in an HTML template and return it, or to convert the data to JSON and return that instead.
这个简单的例子(用Perl编写,请参阅更多上下文的链接)检查查询字符串参数,以确定它是否应该将它在HTML模板中提取的数据放回并返回,或者将数据转换为JSON并返回。
if ($view eq "json") {
my $data = $json->convert_blessed->encode($vars);
print $q->header('application/json;charset=utf-8'), $data;
return;
}
my $output;
$tt->process('html.tt', $vars, \$output)
|| die $tt->error(), "\n";
print $q->header('text/html;charset=utf-8'), $output;
#1
responseText is XHR speak for "What the server responds to the request with, excluding the HTTP headers".
responseText是XHR代表“服务器响应请求的内容,不包括HTTP头”。
It is perfectly normal for it to include a complete HTML document if you access a resource designed to respond to a regular form submission.
如果您访问旨在响应常规表单提交的资源,则包含完整的HTML文档是完全正常的。
It sounds like you need to be smarter about what the server responds with.
听起来你需要更聪明地了解服务器的响应。
This simple example (written in Perl, see the link for more context) checks a query string parameter to decide if it should place the data it has fetched in an HTML template and return it, or to convert the data to JSON and return that instead.
这个简单的例子(用Perl编写,请参阅更多上下文的链接)检查查询字符串参数,以确定它是否应该将它在HTML模板中提取的数据放回并返回,或者将数据转换为JSON并返回。
if ($view eq "json") {
my $data = $json->convert_blessed->encode($vars);
print $q->header('application/json;charset=utf-8'), $data;
return;
}
my $output;
$tt->process('html.tt', $vars, \$output)
|| die $tt->error(), "\n";
print $q->header('text/html;charset=utf-8'), $output;