[英]getting [object, object] when dropdown value is selected - instead of table
I am coming to a problem where I have a dropdown with jsf tags and when I select a dropdown value - it shows [Object, object]
. 我遇到的一个问题是,我有一个带有jsf标签的下拉列表,而当我选择一个下拉列表值时-它显示
[Object, object]
。 I try to convert from object to string using JSON.stringify(data);
我尝试使用
JSON.stringify(data);
从对象转换为字符串JSON.stringify(data);
but it did not quite work. 但效果不佳。 Can anyone help me solve this issue.
谁能帮我解决这个问题。 I have a search input where the values show a html table - I want to do the same with my dropdown.
我有一个搜索输入,其中的值显示了html表-我想对下拉菜单进行相同的操作。 thanks for the help.
谢谢您的帮助。
Here is my code 这是我的代码
$('#sJobClass').on('change', function() {
var jobClassCd = $(this).val();
if (jobClassCd !== 0) {
$.post('http://localhost:8080/myApp/JobSearchItem.xhtml',
$('#searchForms').serialize(),
function(data) {
$('#results').append(data + '<br/><br/>');
// $('#results').append($(text).find('table'));
console.log(data);
JSON.stringify(data);
});
$("#clearone").show();
}
});
HTML with JSF tags 带有JSF标签的HTML
<select class="selectMenuSize" id="sJobClass" name="sJobClass">
<option value="">choose</option>
<c:forEach items="#{myBean.jobSearchItems}" var="searchItem">
<option value="#{searchItem.getSearchValue()}" id="searchInputField"
name="searchInput">#{searchItem.toString()}</option>
</c:forEach>
</select>
Data 数据
{
id: "11111",
label: "PROGRAMMER (1111) ",
value: "11111"
}
You appear to be calling JSON.stringify(data)
(which is correct) but opting to ignore the result and instead use the raw value of data
(which is not). 您似乎正在调用
JSON.stringify(data)
(这是正确的),但选择忽略结果,而是使用data
的原始值(不是)。
Try this as your callback function: 尝试将此作为您的回调函数:
function(data) {
$('#results').append(JSON.stringify(data) + '<br/><br/>');
});
you append all the return object and they have multiple attribution witch one you need to display in results ? 您附加所有返回对象,它们就有多个属性需要在结果中显示?
$('#results').append(data.label + '<br/><br/>'); $('#results').append(data.id + data.label + '<br/><br/>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.