Wednesday, July 20, 2016

Jquery load ignoring object and not posting

Leave a Comment

I have a strange situation where I am loading some content into a modal using jQuery load(). This is working perfectly in development but on the production server, the object is being ignored and only sending a GET request. I've checked the typeof object which is successful and tried other variations in the second parameter of the load method. Never had this before.

var $modal = $('#ajax-modal');           $('body').modalmanager('loading');          //_token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');          setTimeout(function(){              var _post = {ajax:true, lead:lead, type:type };              $modal.load('leads/action/', _post, function(){             });         }, 1000); 

Headers:

Request URL:http://mydomain/leads/action Request Method:GET Status Code:200 OK 

I'm also getting Provisional headers are shown in Chrome.

The script should POST to the url and load the data into the modal. Below are the headers sent when I'm on my local server:

ajax:true lead:4273 type:reminder 

Any pointers would be appreciated

1 Answers

Answers 1

It's a Redirection problem: When you POST your request to leads/action/ your server redirects it to leads/action with a GET request. You can resolve this by removing the trailing slash:

$modal.load('leads/action', _post, function(){                        //^ Here  }); 

I hope this will help you.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment