Frage

I am trying to implement the pushState method, but cannot get it to work properly. The history.pushState line gets triggered without performing the desired change of browser window URL. No error messages are appearing in the console.

The problem is probably the last @href argument, because if I replace it with something like "#test", the browser window URL changes to /#test.

What am I missing here?:

paramsBtn = $(".reorder-orders")
paramsBtn.off "click"
paramsBtn.click (e) ->
    el = $(e.currentTarget)
    reorder = el.attr("reorder")

    $.ajax
        type: "get"
        dataType: "script"
        data:
            view: reorder
        url: "/api/orders/reorder_orders"
        success: (data, status, xhr) ->
            history.pushState null, "", @href
            false

        error: (xhr, textStatus, errorThrown) ->
            console.log "Error while organizing"
War es hilfreich?

Lösung

by @href you probably want to refer to the button's href attribute. You cannot access to this anymore in $.ajax's callback function, so you should store what you need in a variable before.

Right after reorder = el.attr("reorder"), add href = @href

Then update your pushState line like this: history.pushState null, "", href

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top