Coldfusion Jquery Ajax数据格式

Coldfusion Jquery Ajax数据格式,jquery,ajax,coldfusion,Jquery,Ajax,Coldfusion,功能是 $.ajax({ type: 'Get', url: '/services/user.cfc?method=GetCompanyJson', data: 'Companyid=' + ui.item.id, datatype: 'json', error: function(xhr, textStatus, errorThrown) { // show error alert(errorThrown)}, success: function(response, textStatus, j

功能是

$.ajax({
type: 'Get',
url: '/services/user.cfc?method=GetCompanyJson',
data: 'Companyid=' + ui.item.id,
datatype: 'json',
error: function(xhr, textStatus, errorThrown) {
// show error
alert(errorThrown)},
success: function(response, textStatus, jqXHR) {
alert(response);
$('#Company_Name').val(response.name);                  
}
});

如何在Javascript中访问此数据?

将重新格式化的格式更改为普通格式
"{"phone":"8634500","state":"CA","zip":"92618","name":"Taco Bell Corp","ID":"2200","city":"Irvine","address_line_2":"","address_line_1":"1 Glen Bell Way"}"
像这样

success: function(response, textStatus, jqXHR) {
    console.log(response.phone);
    console.log(response.state);
}

现在,您可以在Ajax成功请求中访问它。

尝试在响应对象上使用jQuery.parseJSON(),如下所示:

<cffunction name="GetCompanyJson" access="remote" returntype="struct"     returnformat="plain">
我认为这应该行得通。您还可以将.ajax()调用替换为.getJSON(),该调用将返回解析后的对象


response.phone给我的“未定义”
datatype
应该是
datatype
,这造成了很大的差异,但是;对象{电话:“8634500”,状态:“CA”,邮政编码:“92618”,名称:“塔科贝尔公司”,ID:“2200”}是我现在得到的。地址1填充到中的值中$(“#公司地址1”).val(应答.地址行1);但是名称不会使用:$(“#Company_name”).val(response.name)显示;您确定id是“公司名称”吗?JavaScript是区分大小写的,因为您的其他字段示例都是小写的,这可能是您的问题。这是一个很好的捕获。但以下是我如何将数据显示到屏幕上$(“#公司名称”).val(response.name)$(“#公司地址1”).val(应答.地址行1)$(“#公司地址2”).val(应答.地址行2)$(#Company_City').val(response.City)$(#company_State').val(response.State)$(“#company_zip”).val(response.zip)$(“#公司电话”).val(response.phone);但是名称、城市和州元素没有填写。
<cffunction name="GetCompanyJson" access="remote" returntype="struct"     returnformat="plain">
success: function(response, textStatus, jqXHR) {
    var RespObj = jQuery.parseJSON(response);
    console.log(RespObj.phone);
    console.log(RespObj.state);
}