jquery-post

$.post() doesn't send data as json but as x-www-form-urlencoded instead

自古美人都是妖i 提交于 2019-11-27 12:46:37
问题 This one is really weird. I've multiple $.post() in the code but there is one dunno why sends the json parameters as x-www-form-urlencoded instead and therefore doesn't work. Here's the code: $.post("/Route/SaveTransportProperties", { properties: JSON.stringify(propArray), currTravelBox: JSON.stringify(travelBoxObj), accessToken: getAccessToken()}, function(data) { //DO STUFF }); The XHR looks like this in Firefox: Any ideas why is this happening? I also enforced the type as 'json' but doesn

jQuery add CSRF token to all $.post() requests' data

佐手、 提交于 2019-11-27 04:14:23
I am working on a Laravel 5 app that has CSRF protection enabled by default for all POST requests. I like this added security so I am trying to work with it. While making a simple $.post() request I received a 'Illuminate\Session\TokenMismatchException' error because the required form input _token was missing from the POST data. Here is an example of a $.post request in question: var userID = $("#userID").val(); $.post('/admin/users/delete-user', {id:userID}, function() { // User deleted }); I have my CSRF token stored as a meta field in my header and can easily access it using: var csrf_token

RedirectToAction not working after successful jquery ajax post? [duplicate]

会有一股神秘感。 提交于 2019-11-26 19:34:54
问题 This question already has answers here : How can I RedirectToAction within $.ajax callback? (4 answers) Closed 6 years ago . The following does not redirect my page: Here is the MVC code: [HttpPost] public ActionResult GoHome() { return RedirectToAction("Index", "Home"); } Here is the ajax post: $.support.cors = true; $.ajax({ type: "POST", url: "http://localhost/UserAccount/GoHome", dataType: 'json', crossDomain: true }); The post is successful and when it hists the GoHome action it does not

jQuery add CSRF token to all $.post() requests' data

旧巷老猫 提交于 2019-11-26 12:42:31
问题 I am working on a Laravel 5 app that has CSRF protection enabled by default for all POST requests. I like this added security so I am trying to work with it. While making a simple $.post() request I received a \'Illuminate\\Session\\TokenMismatchException\' error because the required form input _token was missing from the POST data. Here is an example of a $.post request in question: var userID = $(\"#userID\").val(); $.post(\'/admin/users/delete-user\', {id:userID}, function() { // User