Pjax submit form URL redirection

PJAX documentation states that Github uses $.pjax.submit()to send the form Gist . The desired feature of the ajax form submission, which Github perfectly implements, is that the URL is redirected from the form actionto the newly created URL (in this case, one of them contains a new server-side gist identifier).

For example, from this:

https://gist.github.com/gists //  form action

:

https://gist.github.com/tim-peterson/5019589 //assume this ID is generated server side

I worked the same way as on my site (i.e. the page itself is redirected to the equivalent of https://gist.github.com/tim-peterson/5019589 ), but I can not redirect the URL (it remains https: / /gist.github.com/gists ).

Is this completely a server side issue (setting up headers?) Or is there something in pjax that I am missing? I am using the pjax version downloaded today, so it cannot be that I am using a more complex version of pjax.

+5
source share
3 answers

Did you find a solution? I had a similar problem.

Basically you need to set the X-PJAX-URL property in the response header. The value must be the same as the request URL.

In Laravel, I did it like this ...

App::after(function($request, $response)
{
  $response->headers->set('X-PJAX-URL', $request->getRequestUri());
});
+5
source

/ $.pjax.submit(), , . , . , , , PJAX .

$("#save").click(function(e) {

  e.preventDefault();
  dataString = $("#form").serialize();

  $.ajax({
    type: "POST",
    url: $("#form").attr("action"),
    data: dataString,
    dataType: "json",
    success: function(data)
    {
      // Handle the server response (display errors if necessary)

      $.pjax({
        timeout: 2000,
        url: data.url,
        container: '#main-content'
      });

    }
  });
});
+1

This happens if the HTML response does not contain the initial PJAX container

0
source

All Articles