0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ajax使って非同期処理を動的にしてなくてちょっとちびった話

Posted at

非同期処理が本番環境で動かない、、!

ということで、
本番環境にデプロイしたけど非同期処理ができてなくて「?」となっておりました

開発環境では動いてたのに、、、!
なんでだ!

と焦っておりましたが、
非同期処理を行うエンドポイントがガッチリハードコーディングされておりました。

<script>
    $(document).ready(function() {
        $('.submit').click(function(e) {
            $.ajax({
                url: 開発環境のURL/admin/clients', // サーバーのエンドポイントが開発URLに固定されとる。
                type: 'GET',
                success: function(response) {
                    $('#formRow').hide();
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.error(textStatus, errorThrown);
                }
            });
        });
    });
</script>

こんな感じでね。
(ちなみにこれはボタンポチったら入力フォームにhideつくやつ。)

さて、これでは当然本番環境のURLでは、URLかわっちまうから動的に変更せねば、、、!
ということです。

動的URLを書けばオッケー

url: window.location.origin + '/admin/clients', // サーバーのエンドポイント。

こういうことですわな

window.location.origin
こいつがoriginのURLとってきてくれる、えらい。

を使ってadmin画面のクエリを追加することで、
動的なエンドポイントで非同期処理ができたというわけです。

やったぜ。

先方から連絡来た時はちょっと漏らした。

さーてとlaravel backpackでもサクッとカスタマイズしますか!!
(進捗遅れてる)

おわり。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?