gpt4 book ai didi

jquery - jQuery ajax post 时出现 SystemStackError(堆栈级别太深)

转载 作者:行者123 更新时间:2023-12-01 04:39:42 28 4
gpt4 key购买 nike

我有一个表单,当用户在文本字段中输入某些值时,我想自动填充其他字段,但它不断返回 SystemStackError (堆栈级别太深)。这是文件:

路线.rb

scope :places, controller: :places, as: :places do
post :postcode, action: :postcode, as: :postcode
end

form.html.erb

<form>
<input type="text" class="input_postcode">
<input type="text" class="input_state">
</form>

main.js

$(document).on('change', ".input_postcode", function(e) {
e.stopPropagation();
e.preventDefault();
var postcode = $(this).val();
$.post( 'places/postcode', { postcode: postcode }, function(data) {
$(".input_state").val(data.state);
return false;
}, 'json');
return false;
});

places_controller.rb

def postcode
place = Place.where(postcode: postcode).first
state = place.state.name
respond_to do |format|
format.js { render json: { state: state } }
end
end

我在控制台中得到这个结果:

SystemStackError (stack level too deep):
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
app/controllers/places_controller.rb:4:in `postcode'
(keeps going the infinite loop...)

places_controller 中的第 4 行是 place = Place.where(postcode: postcode).first 行。

我不知道我做错了什么。希望有人能帮助我!

最佳答案

您收到SystemStackError(堆栈级别太深),因为您的操作名称是postcode,并且您的对象变量名称/方法也被命名为postcode >.

  place = Place.where(postcode: postcode).first

当您传入 postcode 属性时会发生错误,因为它与方法/操作具有相同的名称。

要修复错误,请重命名操作和路由名称。

关于jquery - jQuery ajax post 时出现 SystemStackError(堆栈级别太深),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41420883/

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