Tag: 发布

根据单击的按钮将相同的表单发布到不同的操作

我在StackOverflow上有类似的post,但也许我的误解更为重要。 我有一个动作索引()和索引视图的渲染。 从Index()视图取决于单击的按钮[HttpPost]索引()或[HttpPost] Search()必须调用因为我发布了一些数据。 发布到不同操作的唯一方法是使用jQuery吗? 如果jQuery是唯一的方法,如果我的操作返回视图(完整的Html页面),我必须从$ .post清理整个文档元素并用我的视图html填充它? 我对这一切都很陌生,非常感谢! @using (Html.BeginForm()) { … … } public ActionResult Index(string lang) { return View(); } //Perhaps this action is needed [HttpPost] public ActionResult Index(string lang, string startDate) { return View(); } [HttpPost] public ActionResult Search(string lang, string startDate) { return View(); ]

无法获得jQuery ajax POST工作

如果我在下面的代码中将类型设置为’GET’,它可以工作,但是我无法使用’POST’。 ajaxPostTest.html … $(document).ready(function(){ $.ajax({ url: “ajaxPostTest_server.php”, data: {“fruit1”: “rasp”, “fruit2”: “bramble”}, type: ‘POST’, dataType: ‘json’, contentType: “application/json; charset=utf-8”, success: function(data){ $(“#returned”).append(data.fruit1); }, error: function(jqXHR, textStatus, errorThrown){ alert(“error”) ; } }); }); returned: ajaxPostTest_server.php … 浏览器的预期输出是…… returned: rasp 我实际上是在尝试与ASP.NET Web服务器进行交互,我想首先确认我的ajax正在工作(并且我正确地理解了ajax) – 因此这个简化的代码。 Firebug调试…… Response Headersview source Date Fri, 23 Sep 2011 14:57:37 GMT Server Apache/2.2.14 […]

将JialResult ActionMethod中的PartialView返回到ajaxpost并将PartialView显示为Modal弹出窗口

我试图将部分视图或任何其他视图从操作方法返回到ajaxpost。 我想从ajax成功函数或以其可能的方式显示内容ParitalView作为Jquery Modal弹出窗口。 带有注册表单的“MyRegistrationView”下面提到了表单提交按钮上的ajax post call。 $.ajax({ url: url, //http://localhost/MyRegistration/RegisterUser type: ‘POST’, dataType: ‘json’, data: ko.toJSON(RegistrationInfoModel), contentType: “application/json; charset=utf-8”, success: function (result) { //Do something }, error: function (request, status, error) { //Do something } }); 上面的ajax调用使用如下的action方法进入名为“MyRegistrationController”的Controller。 [HttpPost] public JsonResult RegisterUser(RegistrationInfo model) { //Register User …. if(successful) { return Json(new { data = PartialView(“_ShowSuccessfulModalPartial”) }); […]

如何在$ .post jQuery中等待响应

PHP以1-2秒延迟返回值jQuery.post不等待响应。 您如何看待,是否可以解决该问题并等待响应? $.post( sSource, aoData, function (data) { oCache.lastJson = jQuery.extend(true, {}, data); if ( oCache.iCacheLower != oCache.iDisplayStart ) { data.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower ); } data.aaData.splice( oCache.iDisplayLength, data.aaData.length ); abc(oCache); fnCallback(data); },”json” ); 注意相同的function与get工作得很好 $.getJSON( sSource, aoData, function (json) { /* Callback processing */ oCache.lastJson = jQuery.extend(true, {}, json); if ( oCache.iCacheLower != oCache.iDisplayStart ) […]

如何从jQuery的$ .ajax()函数调用servlet

我试图从jQuery的.ajax()函数调用一个servlet。 目前我不认为我甚至会调用servlet或将paramaters传递给它,但是很多Google搜索似乎没有帮助。 有任何想法吗? 这是我的HTML: function login(){ $(“#loading”).hide(); var email = document.nameForm.email.value; $.ajax({ type: “GET”, url: “ProcessForm”, data: “email=”+email, success: function(result){ alert(result); } }); } My AJAX This time it’s gonna work 电邮加载 还有我的web.xml ajaxtry index.html index.htm index.jsp default.html default.htm default.jsp ProcessForm com.ajaxtry.web.ProcesFormServlet ProcessForm /ProcessForm servlet目前只是一个模板: package com.ajaxtry.web; // imports here public class ProcessFormServlet { public […]

Jquery POST在spring mvc中给403禁止错误

我想使用$ .POST进行ajax调用。 但我得到403错误。 但GET工作得非常好。 我的代码是: var url = “/xyz/abc/subscribe?name=”+name; $.post(url, function(data){ alert(data); }); 控制器代码是: @RequestMapping(value = “/xyz/abc/subscribe”, method = RequestMethod.POST) public @ResponseBody String subscribe(@RequestParam(“name”) String name) throws Exception { String message = “TESTING”; return message; } 但是我收到403错误。

如何使用Jquery AJAX发布多维数组?

我一直在使用Serialize()来传递带有Post()的复选框表单数据,用于可以容纳同一类别的多个项目的篮子。 当我使用提交按钮发布它时,它可以正常工作,并传递多个值并显示在一个类别下。 但是当我使用Jquery serialize()时,它每个类别只显示一个项目,总共只显示两个类别。 这是一个数组问题,但我无法解决。 是否有一个替代JQuery函数我应该用于传递一个多维数组?

jQuery AJAX / POST不向PHP发送数据

所以我现在有这个问题已经有一段时间了,我知道这个话题有无数问题,相信我,我尝试了所有解决方案,但仍然无效。 这是最简单的例子,在我的情况下不起作用 jQuery的: $.ajax({ url: “ajax/add-user.php”, type: “POST”, data: {name: ‘John’}, success: function(data){ console.log(data); } }); PHP echo json_encode($_POST); 而已。 我总是回来一个空数组作为回应。 我尝试使用serialize()获取data:但响应始终为空。 我没有得到任何错误,只是一个空数组,当我应该得到发布的值。 例如,如果在php中我尝试echo一些硬编码变量,我会得到它们,但$_POST和$_GET不起作用。 我如何识别问题的任何解决方案或方法? 谢谢。 编辑/解决方案 好的,所以似乎问题是.htaccess重写了url并删除了扩展名。 在网络选项卡中,确实永久地移动了请求。 从ajax url中删除.php扩展名:解决了它。 谢谢你,对不起浪费时间。 干杯

使用jQuery发布到ASP.Net webapi

遇到麻烦: 我做了这个简单的测试,警报会弹出文本“test return simple”: jQuerypost: $.post(“http://www.localhost/webapi/api/corkboard/test/”, jsonData) .done(function(data){ alert(data); }); Asp.Net WebAPI: [HttpPost] public string test() { return “test return simple”; } 但是当我通过添加参数来更改WebAPI时: public string test(string JSONData) { var jData = Json.Decode(JSONData); return “test return: ” + jData.Filter; } 我收到以下错误消息: “没有找到与请求URI匹配的HTTP资源’ http://www.localhost/webapi/api/corkboard/test/ ‘ 坚持并会感激任何想法…谢谢!

通过JQuery使用WCF POST进行400错误请求HTTP响应

无法让我的JQuery POST被WCF服务接受。 这是来自javascript的POST: function jqueryPost() { var url = “/LoggingTest”; $.post(url, { message: “test message” }); } 这就是我通过接口接受POST的方式: [OperationContract] [WebInvoke(Method = “POST”, UriTemplate = “/LoggingTest”, BodyStyle = WebMessageBodyStyle.Bare)] void LoggingTest(string message); 并实施: public void LoggingTest(string message) { log.Debug(message, null); } 当我调用函数jqueryPost时,我在Web检查器中看到了400 Bad Request的HTTP响应。 不确定如何让POST请求工作。 (在7/1上添加) @James,这是web检查器的输出: http:// localhost:4252 / LoggingTest HTTP信息 请求方法:POST 状态代码:400错误请求 请求标题 接受: […]