ajax添加response,jQuery AJAX response type

I'm trying to make a working example of jQuery 1.9.1 AJAX + icanhaz/mustache. This is my template:

{{#users}}

Username: {{ username }}, fullname: {{ fullname }}{{/users}}

and this is my JavaScript:

$(document).ready( function() {

$("#user-btn").click(function() {

$.ajax({

type: "GET",

url: "../php/client/json.php",

data: {

type: "users"

}

}).done(function( response ) {

var element = $('#dialog-message');

element.html("

  • ");

element.append(ich.user(response));

element.append("

");

});

});

The AJAX response from this address looks something like:

{"users":[{"username":"jd","fullname":"John Doe"},{"username":"jl","fullname":"John Lennon"}]};

With the following code, icanhaz cannot render anything for me. I spent some time with javascript console and found out that the typeof response is string and I expected object. Icanhaz also expects object - that's why it didn't manage to render the correct response.

Am I doing something wrong or am I just a poor newbie who didn't know that jquery.ajax returns string responses always? If so, how should I handle them?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值