<script language="JavaScript">
var result = {};
var data;
function load_metadata (id) {
$.ajax({
url: "/video/metadata",
type: "POST",
data: id,
cache: false,
//dataType: "json",
//contentType: 'application/json',
success: function(data) {
result = data;
},
error: function(e, xhr){
alert('slideshow data load error: ');
}
});
alert(result.toSource()); //({})
}
</script>
/video/metadata(梅森组件)
<%class>
use JSON;
has 'data';
</%class>
<%init>
use Data::Dumper;
print STDERR Dumper($.data); # $VAR1 = '"815"'
my $item_hash->{'item'} = "test"; # Valid JSON in JSONLint.com
my $json = to_json($item_hash, { ascii => 1 });
print STDERR Dumper($json); # $VAR1 = '{"item":"test"}';
</%init>
<% $json %>
它返回页面的每个 html 元素,而不是来自组件调用的 json!
指定数据类型/内容类型给出解析器错误