Ask A Question


You’re not receiving notifications from this thread.

jQuery.ajax url: rails

JP asked in Rails

In my code I have this button

<button class="btn btn-success btn-lg" id="check_module">Pay</button>

In my code I have this button

Expand snippet
when clicked on iframe opens from this javascript code

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>

<%= javascript_tag do %>
  $("#check_module").click(function () {
    IMP.init(''); //iamport 대신 자신의 "가맹점 식별코드"를 사용하시면 됩니다
      merchant_uid : "<%= @merchant_uid %>",
      name : '결제테스트',
      amount : <%= @price %>,
      buyer_email : '<%= %>',
      buyer_name : '<%= %>',
      buyer_tel : ' no phone ',
      buyer_addr : ' course name: no address',
      buyer_postcode : ' no postcode ',
      m_redirect_url: "https://url"
    }, function(rsp) {
      if ( rsp.success ) {// Successful payment: Successful payment approval or issuance of a virtual account
      // HTTP request using jQuery
          url: "<%= payment_complete_path(:item_id => @item) %>", // Merchant server
          method: "POST",
          headers: { "Content-Type": "application/json" },
          data: {
              imp_uid: rsp.imp_uid,
              merchant_uid: rsp.merchant_uid
      }).done(function (data) {

        // Logic executed on successful response from the merchant server through the payment API
      } else {
        var msg = '결제에 실패하였습니다.';
        msg += '에러내용 : ' + rsp.error_msg;
<% end %>

but after submitting the form the transaction goes through successfully but it stays on the page

how can I make it to go to this url or this action

  url: "<%= payment_complete_path(:item_id => @item) %>", // Merchant server

in my controller ?

Any help will be greatly appreciated. Thank you!

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.