gpt4 book ai didi

javascript - Rails - AngularJS 将 http.get 作为 html 格式请求发送

转载 作者:行者123 更新时间:2023-11-28 07:38:06 26 4
gpt4 key购买 nike

我有这段 angularjs 代码

  $http.get(sprintf("/posts/%s", post.id)).
success(function(data, status, headers, config) {
$scope.post = data;
})

我期望在后端(rails)中获取json格式请求

respond_to do |format|
format.html
format.json { render json: @post}
end

但是我收到了 html 格式请求。

我缺少什么吗?感谢您的帮助。

最佳答案

最简单的方法是:

$http.get(sprintf("/posts/%s.json", post.id)).
success(function(data, status, headers, config) {
$scope.post = data;
});

关于javascript - Rails - AngularJS 将 http.get 作为 html 格式请求发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28378500/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com