天道酬勤,学无止境

jquery-post

带有序列化和数据数组的jQuery post()(jQuery post() with serialize and array of data)

问题 我无法在mvc 3中过帐时获取集合值。它返回null。 $.post("/Work/Post", { vm: $('#myForm').serializeArray(), 'collection': ['a', 'b', 'c'] }); //Or var data = $('#myForm').serializeArray(); data.push({ name: 'collection', value: ['a', 'b', 'c'] }); $.post("/Work/Post", data); //Or var data = $('#myForm').serializeArray(); data.push({ name: 'collection[]', value: ['a', 'b', 'c'] }); $.post("/Work/Post", data); 回答1 传递数组时,我遇到了类似的问题。 而不是使用$.post使用$.ajax并设置traditional选项= true ... $.ajax({ type: "POST", url: "Work/", traditional: true, data: { collection: ['a','b','c'] } }); traditional: true选择很重要 回答2 通过常规的.ajax()调用

2021-05-13 18:59:43    分类:技术分享    jquery   jquery-post

How to continue form submission after an AJAX call?

I want to validate user entries on a WordPress post upon hitting the submit button, display an error message is there are problems, and submit the form if everything is OK. I have a PHP function that does the checking, returning true if data in form_data is OK, some error code otherwise. The following JavaScript issues the AJAX request, and was supposed to continue submitting the form upon successful checking, but it doesn't: jQuery(document).ready(function() { jQuery('#post').submit(function() { var form_data = jQuery('#post').serializeArray(); var data = { action: 'ep_pre_submit_validation'

2021-05-03 01:46:57    分类:问答    javascript   ajax   jquery   jquery-post

成功的jQuery Ajax发布后,RedirectToAction无法正常工作吗? [复制](RedirectToAction not working after successful jquery ajax post? [duplicate])

问题 这个问题已经在这里有了答案: 如何在$ .ajax回调中执行RedirectToAction? (4个答案) 7年前关闭。 以下内容不会重定向我的页面:这是MVC代码: [HttpPost] public ActionResult GoHome() { return RedirectToAction("Index", "Home"); } 这是ajax帖子: $.support.cors = true; $.ajax({ type: "POST", url: "http://localhost/UserAccount/GoHome", dataType: 'json', crossDomain: true }); 发布成功,并且在发出GoHome操作通知后,它不会重定向到Home Controller的Index Action。 回答1 您无法从AJAX帖子重定向。 您可以返回要将浏览器重定向到的URL,然后从Javascript重定向。 控制器 [HttpPost] public ActionResult GoHome() { return Json(Url.Action("Index", "Home")); } Java脚本 $.ajax({ type: "POST", url: "http://localhost/UserAccount/GoHome"

2021-04-29 07:47:54    分类:技术分享    c#   jquery   post   asp.net-mvc-2   jquery-post

jQuery将CSRF令牌添加到所有$ .post()请求的数据中(jQuery add CSRF token to all $.post() requests' data)

问题 我正在使用Laravel 5应用程序,该应用程序默认为所有POST请求启用CSRF保护。 我喜欢这种增加的安全性,因此我正在尝试使用它。 在发出简单的$.post()请求时,我收到了'Illuminate\Session\TokenMismatchException'错误,因为POST数据中缺少所需的表单输入_token 。 这是一个有关$ .post请求的示例: var userID = $("#userID").val(); $.post('/admin/users/delete-user', {id:userID}, function() { // User deleted }); 我将CSRF令牌存储为标头中的meta字段,可以使用以下命令轻松访问它: var csrf_token = $('meta[name="csrf-token"]').attr('content'); 是否可以将其附加到所有传出的$.post()请求的json数据上? 我尝试使用标头,但Laravel似乎无法识别它们- var csrf_token = $('meta[name="csrf-token"]').attr('content'); alert(csrf_token); $.ajaxPrefilter(function(options, originalOptions, jqXHR)

2021-04-10 12:57:35    分类:技术分享    jquery   ajax   laravel   laravel-5   jquery-post

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

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

2021-03-29 14:53:08    分类:问答    jquery   ajax   laravel   laravel-5   jquery-post