I want to set the value entered for url_for in javascript_tag

Asked 1 years ago, Updated 1 years ago, 39 views

I'd like to enter a number in the text field and get it with ajax.

<%=javascript_tag do%>
jQuery(function($){
  $('input[id^="multi_entry_user_id"]').focusout(function(e){
    $.ajax({
      type: "GET",
      url: "<%=juser_json_multi_entries_url(User.first, format::json)%>",
      data —e.target.value,
      dataType: "script",
      callback: null,
      success: function(data, status, xhr) {
        console.log('hoge success:'+status);
      },
      error: function(data, status, xhr) {
        console.log('hoge error:'+status);
      }
    });
  });
});
<%end%>

Please tell me how to set the User.first part to the user input value.

ruby-on-rails jquery

2022-09-29 22:45

1 Answers

I am writing to let you know that I solved myself.

First, generate HTML like the following……

<div class="col-sm-2"data-user-url="http://locahost:3000/multi_entries/user_json/99999.json">

I have processed the URL string with the following javascript.

vart=$(this).close("[data-user-url]").data('user-url');
var url = t.replace("99999.json", e.target.value + ".json");

Replacing the string "999999" is not cool...(>_<)


2022-09-29 22:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.