如果Ajax请求失败,我想捕获错误并显示相应的消息.
我的代码如下所示,但我无法捕获失败的Ajax请求.
function getAjaxData(id)
{
$.post("status.ajax.php", {deviceId : id}, function(data){
var tab1;
if (data.length>0) {
tab1 = data;
}
else {
tab1 = "Error in Ajax";
}
return tab1;
});
}
Run Code Online (Sandbox Code Playgroud)
我发现,当Ajax请求失败时,永远不会执行"Ajax中的错误".
如果失败,我如何处理Ajax错误并显示相应的消息?
Microsoft最近(12-29-2011)发布了一个更新,以解决.NET Framework中的几个严重安全漏洞.MS11-100引入的修复之一暂时缓解了涉及哈希表冲突的潜在DoS攻击.看来此修复程序会破坏包含大量POST数据的页面.在我们的例子中,在具有非常大的复选框列表的页面上.为什么会这样呢?
一些非官方消息来源似乎表明MS11-100对回发项目的限制为500.我找不到确认这一点的Microsoft源代码.我知道View State和其他框架功能会占用这个限制.是否有任何配置设置来控制此新限制?我们可以不使用复选框,但它对我们的特定情况很有效.我们也想应用补丁,因为它可以防止其他一些令人讨厌的事情.
该公告通过限制可以为单个HTTP POST请求提交的变量数来修复DOS攻击向量.默认限制为500,对于正常的Web应用程序来说应该足够了,但仍然足够低以抵消德国安全研究人员所描述的攻击.
编辑:带有限制示例的源代码(看起来是1,000,而不是500)创建标准MVC应用程序并将以下代码添加到主索引视图:
@using (Html.BeginForm())
{
<fieldset class="fields">
<p class="submit">
<input type="submit" value="Submit" />
</p>
@for (var i = 0; i < 1000; i++)
{
<div> @Html.CheckBox("cb" + i.ToString(), true) </div>
}
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
此代码在补丁之前有效.以后它不起作用.错误是:
[InvalidOperationException:由于对象的当前状态,操作无效.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()+82 System.Web.HttpValueCollection.FillFromEncodedBytes(Byte [] bytes,Encoding encoding)+111
System.Web. HttpRequest.FillInFormCollection()+307
我正在使用cURL命令行实用程序将HTTP POST发送到Web服务.我想将文件的内容包含在POST的正文实体中.我已尝试使用-d </path/to/filename>类似信息的其他变体--data </path/to/filename> --data-urlencode </path/to/filename>等...文件始终附加.我需要它作为身体实体.
更新:我想传递var value给服务器
你好,同样老,同样老...... :)
我有一个名为的表单<form id="testForm" action="javascript:test()">和一个名为的代码区域<code id="testArea"></code>
我正在使用此代码在代码区域中字符串化并显示数据:
var formData = form2object('testForm');
document.getElementById('testArea').innerHTML = JSON.stringify(formData, null, '\t');
var value = JSON.stringify(formData, null, '\t');
Run Code Online (Sandbox Code Playgroud)
我想要的是将此数据发送到JSON文件.我一直在研究这个项目:http://ridegrab.com/profile_old/如果按下Submit Query按钮,你会看到页面的头部填充.
另外我想用这段脚本发送数据:
function authenticate(userName, password) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: 'username:password@link to the server/update',
dataType: 'json',
async: false,
//json object to sent to the authentication url
data: '{"userName": "' + userName …Run Code Online (Sandbox Code Playgroud) 我想查看Chrome中发送的HTTP POST数据.
数据现在在内存中,我可以重新提交表单.
我知道如果我重新提交服务器会抛出错误,无论如何我可以查看Chrome内存中的数据吗?
我想在Java中使用JSON进行简单的HTTP POST.
我们说URL是 www.site.com
并且它采用{"name":"myname","age":"20"}标记'details'为例如的值.
我将如何创建POST的语法?
我似乎也无法在JSON Javadocs中找到POST方法.
我正在尝试在Swift中运行HTTP请求,将POST 2参数发送到URL.
例:
链接: www.thisismylink.com/postName.php
PARAMS:
id = 13
name = Jack
Run Code Online (Sandbox Code Playgroud)
最简单的方法是什么?
我甚至不想阅读回复.我只是想发送它来通过PHP文件对我的数据库进行更改.
我正在尝试向servlet发送POST请求.请求以这种方式通过jQuery发送:
var productCategory = new Object();
productCategory.idProductCategory = 1;
productCategory.description = "Descrizione2";
newCategory(productCategory);
Run Code Online (Sandbox Code Playgroud)
newCategory在哪里
function newCategory(productCategory)
{
$.postJSON("ajax/newproductcategory", productCategory, function(
idProductCategory)
{
console.debug("Inserted: " + idProductCategory);
});
}
Run Code Online (Sandbox Code Playgroud)
和postJSON是
$.postJSON = function(url, data, callback) {
return jQuery.ajax({
'type': 'POST',
'url': url,
'contentType': 'application/json',
'data': JSON.stringify(data),
'dataType': 'json',
'success': callback
});
};
Run Code Online (Sandbox Code Playgroud)
使用firebug,我看到JSON正确发送:
{"idProductCategory":1,"description":"Descrizione2"}
Run Code Online (Sandbox Code Playgroud)
但我得到415不支持的媒体类型.Spring mvc控制器有签名
@RequestMapping(value = "/ajax/newproductcategory", method = RequestMethod.POST)
public @ResponseBody
Integer newProductCategory(HttpServletRequest request,
@RequestBody ProductCategory productCategory)
Run Code Online (Sandbox Code Playgroud)
几天前它工作,现在不是.如果需要,我会显示更多代码.谢谢
我正在尝试使用phantomJS(这是一个很棒的工具btw!)为我有登录凭据的页面提交表单,然后将目标页面的内容输出到stdout.我能够使用幻像访问表单并成功设置其值,但我不太确定提交表单和输出后续页面内容的正确语法.到目前为止我所拥有的是:
var page = new WebPage();
var url = phantom.args[0];
page.open(url, function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
console.log(page.evaluate(function () {
var arr = document.getElementsByClassName("login-form");
var i;
for (i=0; i < arr.length; i++) {
if (arr[i].getAttribute('method') == "POST") {
arr[i].elements["email"].value="mylogin@somedomain.com";
arr[i].elements["password"].value="mypassword";
// This part doesn't seem to work. It returns the content
// of the current page, not the content of the page after
// the submit has been executed. Am I …Run Code Online (Sandbox Code Playgroud) 我是HTTP POST到URL http:// laptop:8080/apollo/services/rpc?cmd = execute
使用POST数据
{ "jsondata" : "data" }
Run Code Online (Sandbox Code Playgroud)
Http请求的Content-Type为 application/json; charset=UTF-8
如何从HttpServletRequest获取POST数据(jsondata)?
如果我枚举请求参数,我只能看到一个参数,即"cmd",而不是POST数据.