pjax submit form URL redirection pjax submit form URL redirection codeigniter codeigniter

pjax submit form URL redirection


Did you find any solution to this?I had the similar issue.

Basically you need to set X-PJAX-URL property in response header.It's value should be same as Request URL.

In Laravel, I did it like this...

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


There may be a more-elegant / proper way to do this with $.pjax.submit(), but this is the solution I've been using without any problems. I serialize the form inputs prior to submission, then POST them to my server. Then check the reply from the server to make sure I don't need to prevent the user from going forward before calling my PJAX to continue.

$("#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'      });    }  });});


It happens if response HTML doesn't contain initial PJAX container