link_to_remote方法更新失效

本文探讨了在使用link_to_remote进行AJAX调用时遇到的页面不更新问题,并提供了在不同浏览器环境下的一致性解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   在使用link_to_remote 出现的这样的问题,郁闷

   点击链接,使用link_to_remote实现ajax调用,
   页面:
<% form_for :diary,:url =>{:action => 'creat_diary' } do |form| %>
   <%= error_messages_for 'diary' %>

  <fieldset>
    <legend>日记</legend> 
  
    <p><label for="diary_diary_sort">日记分类</label>
      <span id='diary_sorts'><%= form.select :diary_sort_id, @diary_sorts %></span> 
      <span id='new_diary_sort'>
        <%= link_to_remote '添加分类' ,:url => {:action => 'new_diary_sort',:member_id => @member.id },:update => 'new_diary_sort' %>
      </span> 
    </p>
  
  </fieldset>
  
  <br/>
  <%= submit_tag "确认提交" %>
<% end %>

 

这是代码和调用的页面

def new_diary_sort
    @diary_sort = DiarySort.new   
  end

 

<% form_for :diary_sort,:url =>{:action => 'creat_diary_sort' } do |form| %>
       <%= form.text_field :name  %>                   
<% end %>


点击链接,调用了new_diary_sort方法了(使用了日志输出),但是没有更新页面,检查不到错误,这是怎么回事?

 

在IE6和7中都不执行,在ff中执行正常,sad

 

[I 2025-07-14 08:43:19.216 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab [I 2025-07-14 08:43:19.216 LabApp] Extension Manager is 'pypi'. [I 2025-07-14 08:43:19.219 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-07-14 08:43:19.222 ServerApp] notebook | extension was successfully loaded. [C 2025-07-14 08:43:19.224 ServerApp] Running as root is not recommended. Use --allow-root to bypass. 正在启动数据分析环境... 配置中文字体... 找到中文字体: /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc 已清除缓存: fontlist-v330.json 中文字体配置完成! 启动Jupyter Lab... 访问地址: http://localhost:22001 Token: spacy2024 [I 2025-07-14 08:44:20.675 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-07-14 08:44:20.680 ServerApp] jupyter_server_terminals | extension was successfully linked. [W 2025-07-14 08:44:20.681 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_root' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'token' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'password' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_origin' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_remote_access' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'disable_check_xsrf' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'contents_manager_class' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.685 ServerApp] jupyterlab | error linking extension: The 'contents_manager_class' trait of <jupyter_server.serverapp.ServerApp object at 0x7fae37602ac0> instance must be a type, but 'notebook.services.contents.largefilemanager.LargeFileManager' could not be imported Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2139, in validate value = self._resolve_string(value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2015, in _resolve_string return import_item(string) File "/usr/local/lib/python3.9/site-packages/traitlets/utils/importstring.py", line 33, in import_item module = __import__(package, fromlist=[obj]) ModuleNotFoundError: No module named 'notebook.services' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 381, in link_extension extension.link_all_points(self.serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 258, in link_all_points self.link_point(point_name, serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 243, in link_point point.link(serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 158, in link linker(serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 412, in _link_jupyter_server_extension self.serverapp.update_config(self.config) File "/usr/local/lib/python3.9/site-packages/traitlets/config/configurable.py", line 244, in update_config self._load_config(config) File "/usr/local/lib/python3.9/site-packages/traitlets/config/configurable.py", line 193, in _load_config setattr(self, name, deepcopy(config_value)) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 716, in __set__ self.set(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 690, in set new_value = self._validate(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 722, in _validate value = self.validate(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2141, in validate raise TraitError( traitlets.traitlets.TraitError: The 'contents_manager_class' trait of <jupyter_server.serverapp.ServerApp object at 0x7fae37602ac0> instance must be a type, but 'notebook.services.contents.largefilemanager.LargeFileManager' could not be imported [I 2025-07-14 08:44:20.690 ServerApp] notebook | extension was successfully linked. [I 2025-07-14 08:44:20.872 ServerApp] notebook_shim | extension was successfully linked. [I 2025-07-14 08:44:20.888 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-07-14 08:44:20.890 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-07-14 08:44:20.891 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-07-14 08:44:20.892 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.9/site-packages/jupyterlab [I 2025-07-14 08:44:20.892 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab [I 2025-07-14 08:44:20.893 LabApp] Extension Manager is 'pypi'. [I 2025-07-14 08:44:20.896 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-07-14 08:44:20.899 ServerApp] notebook | extension was successfully loaded. [C 2025-07-14 08:44:20.900 ServerApp] Running as root is not recommended. Use --allow-root to bypass. PS C:\Users\3090\Desktop\Docker\spacy-metabase-docker>
07-15
#include "main.h" uint8_t rsp_buf[TCPS_MAX_DATASIZE]; uint8_t tcp_server_buff[TCPS_MAX_DATASIZE]; static MBTcpCtxTypeDef mbs_ctx; uint8_t Last_SR[8] = {0}; uint8_t Sn_SR[8] = {0}; void mb_tcp_slave_init() { mbs_ctx.req_buff = tcp_server_buff; mbs_ctx.rsp_buff = rsp_buf; mbs_ctx.reg_head = 0; mbs_ctx.reg_range = sizeof(hreg)>>1; mbs_ctx.p_regs = (uint16_t *)&hreg; } uint16_t do_tcp_server(uint8_t * buf,uint8_t sn) { uint16_t len=0; uint8_t remote_ip[4]; Sn_SR[sn] = getSn_SR(sn); if (Last_SR[sn] != Sn_SR[sn]) { Last_SR[sn] = Sn_SR[sn]; log_info("Socket%d Server SR Status => 0x%X. \r\n", sn, Sn_SR[sn]); } switch(Sn_SR[sn]) { case SOCK_CLOSED: update_socket_inactivity(sn); mb_tcp_slave_init(); extern void setKPALVTR(SOCKET i,uint8_t val); setKPALVTR(sn, 1); socket(sn ,Sn_MR_TCP,502,0); break; case SOCK_INIT: listen(sn); break; case SOCK_ESTABLISHED: getSn_DIPR(sn, remote_ip); if( remote_ip[0] == 192 && remote_ip[1] == 168 && remote_ip[2] == 0 && remote_ip[3] == 2) // 防止手操器占用工控机192.168.0.2 Mac { udp_get_mac(sn, SOCKET_NTP, SOCKET_UDP_CH0); } if(getSn_IR(sn) & Sn_IR_CON) { setSn_IR(sn, Sn_IR_CON); } len=getSn_RX_RSR(sn); if(len > 0 && len < TCPS_MAX_DATASIZE) { recv(sn,buf,len); buf[len]=0x00; return len; } break; case SOCK_CLOSE_WAIT: update_socket_inactivity(sn); disconnect(sn); close(sn); break; default: break; } return 0; } void modbus_tcp_poll( uint8_t sn) { uint16_t Recelen=0; uint16_t rsp_len=0; static uint8_t last_link_sts=0; if((getPHYCFGR() & 0x01) == 1)//已连接网线 { if(last_link_sts == 0)//当刚接入网线时重新初始化W5500网络参数 { last_link_sts = 1; } Recelen = do_tcp_server(tcp_server_buff,sn); if (Recelen > 0) { update_socket_activity(sn); mbs_ctx.req_len = Recelen; rsp_len = parse_request(&mbs_ctx); if(rsp_len > 0 && rsp_len < TCPS_MAX_DATASIZE) { send(sn,rsp_buf,rsp_len); } Recelen = 0; } check_socket_timeout(sn); SYSTC(48) } else//已断开网线 { if (last_link_sts == 1)//当刚断开网线时关闭所有socket { close(sn); last_link_sts = 0; } SYSTC(49) } } static int parse_request(MBTcpCtxTypeDef *ctx) { uint16_t i; uint16_t rsp_index; uint16_t rsp_len; uint16_t req_reg_nums; uint16_t req_reg_offset; if(ctx->req_len <= 263) { switch(ctx->req_buff[7]) { case 0x03://read muti regs //copy Transaction ID ctx->rsp_buff[0] = ctx->req_buff[0]; ctx->rsp_buff[1] = ctx->req_buff[1]; //Protocol ID ctx->rsp_buff[2] = 0; ctx->rsp_buff[3] = 0; //Slave ID ctx->rsp_buff[6] = ctx->req_buff[6]; req_reg_offset = ctx->req_buff[8]<<8 | ctx->req_buff[9]; req_reg_nums = ctx->req_buff[10]<<8 | ctx->req_buff[11]; if(req_reg_nums>=0x0001 && req_reg_nums<=0x007d) { if(req_reg_offset>=ctx->reg_head && (req_reg_offset+req_reg_nums-1) <= (ctx->reg_head+ctx->reg_range-1)) { ctx->rsp_buff[4] = ((req_reg_nums<<1) + 0x03)>>8; ctx->rsp_buff[5] = ((req_reg_nums<<1) + 0x03); ctx->rsp_buff[7] = ctx->req_buff[7]; ctx->rsp_buff[8] = req_reg_nums<<1; rsp_index = 9; for(i=0;i<req_reg_nums;i++) { ctx->rsp_buff[rsp_index++] = ctx->p_regs[req_reg_offset-ctx->reg_head+i]>>8; ctx->rsp_buff[rsp_index++] = ctx->p_regs[req_reg_offset-ctx->reg_head+i]; } rsp_len = rsp_index; } else { //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x02; rsp_len = 9; } } else//reg_nums illegal { //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; //rsp exception ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x03; rsp_len = 9; } break; case 0x06://write single regs //copy Transaction ID ctx->rsp_buff[0] = ctx->req_buff[0]; ctx->rsp_buff[1] = ctx->req_buff[1]; //Protocol ID ctx->rsp_buff[2] = 0; ctx->rsp_buff[3] = 0; //Slave ID ctx->rsp_buff[6] = ctx->req_buff[6]; req_reg_offset = ctx->req_buff[8]<<8 | ctx->req_buff[9]; if(req_reg_offset>=ctx->reg_head && (req_reg_offset <= ctx->reg_head+ctx->reg_range-1)) { ctx->p_regs[req_reg_offset-ctx->reg_head] = ctx->req_buff[10]<<8 | ctx->req_buff[11]; //MBPA length ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x06; //func code ctx->rsp_buff[7] = ctx->req_buff[7]; //copy reg offset ctx->rsp_buff[8] = ctx->req_buff[8]; ctx->rsp_buff[9] = ctx->req_buff[9]; //copy reg value ctx->rsp_buff[10] = ctx->req_buff[10]; ctx->rsp_buff[11] = ctx->req_buff[11]; rsp_len = 12; } else { //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x02; rsp_len = 9; } break; case 0x10://write multi regs //copy Transaction ID ctx->rsp_buff[0] = ctx->req_buff[0]; ctx->rsp_buff[1] = ctx->req_buff[1]; //Protocol ID ctx->rsp_buff[2] = 0; ctx->rsp_buff[3] = 0; //Slave ID ctx->rsp_buff[6] = ctx->req_buff[6]; req_reg_offset = ctx->req_buff[8]<<8 | ctx->req_buff[9]; req_reg_nums = ctx->req_buff[10]<<8 | ctx->req_buff[11]; if(req_reg_nums>=0x0001 && req_reg_nums<=0x007d) { if(req_reg_offset>=ctx->reg_head && ((req_reg_offset+req_reg_nums-1) <= (ctx->reg_head+ctx->reg_range-1))) { for(i=0;i<req_reg_nums;i++) { ctx->p_regs[i+req_reg_offset-ctx->reg_head] = ctx->req_buff[i*2+13]<<8 | ctx->req_buff[i*2+14]; } //MBPA length ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x06; //func code ctx->rsp_buff[7] = ctx->req_buff[7]; //copy reg offset ctx->rsp_buff[8] = ctx->req_buff[8]; ctx->rsp_buff[9] = ctx->req_buff[9]; //copy reg nums ctx->rsp_buff[10] = ctx->req_buff[10]; ctx->rsp_buff[11] = ctx->req_buff[11]; rsp_len = 12; } else { //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x02; rsp_len = 9; } } else//reg_nums illegal { //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; //rsp exception ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x03; rsp_len = 9; } break; default://func code Not Supported rsp exception //copy Transaction ID ctx->rsp_buff[0] = ctx->req_buff[0]; ctx->rsp_buff[1] = ctx->req_buff[1]; //Protocol ID ctx->rsp_buff[2] = 0x00; ctx->rsp_buff[3] = 0x00; //Slave ID ctx->rsp_buff[6] = ctx->req_buff[6]; //caculate bytes nums ctx->rsp_buff[4] = 0x00; ctx->rsp_buff[5] = 0x03; ctx->rsp_buff[7] = ctx->req_buff[7] | 0x80; ctx->rsp_buff[8] = 0x01; rsp_len = 9; break; } return rsp_len; } else { return 0; } } 请给我解释一下这段程序,并告诉我可能存在什么问题
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值