使用jquery,我可以使用像这样的ajax从客户端向服务器发送json对象:
var strJSON = '{"event":[{
"dates":[
"2009-10-14","2009-10-15"],
"teams":[
{"id":"0","country":"USA","state":"CA","name":"California Polytechnic State University","subteam":""},
{"id":"1","country":"USA","state":"CA","name":"California State University, Bakersfield","subteam":""},
{"id":"2","country":"USA","state":"CA","name":"California State University, Fresno","subteam":""},
{"id":"3","country":"USA","state":"CA","name":"California State University, Fullerton","subteam":""}]
}]}';
$.ajax({
url: '../ajax/save_event',
type: 'POST',
data: { data : strJSON },
dataType: 'json',
timeout: 8000,
cache: false
});
Run Code Online (Sandbox Code Playgroud)
它运作良好.但是如果JSON字符串变得更大(不确定确切的大小,但大约大5倍),服务器收到的$ _POST数据为空.谁知道为什么?
我正在使用Apache/PHP/jquery.它发生在IE和Firefox上.我需要调整配置设置吗?
这是一个无法通过的字符串示例:
{"events":[{"dates":["2009-10-10","2009-10-11","2009-10-12"],"divisions":[{"level":"Collegiate","name":"Varsity","subdivision":"Division I","rounds":[],"teams":[{"id":"0","country":"USA","state":"CA","name":"California Polytechnic State University","subteam":""},{"id":"1","country":"USA","state":"CA","name":"California State University, Bakersfield","subteam":""},{"id":"2","country":"USA","state":"CA","name":"California State University, Fresno","subteam":""},{"id":"3","country":"USA","state":"CA","name":"California State University, Fullerton","subteam":""},{"id":"4","country":"USA","state":"CA","name":"Stanford University","subteam":""},{"id":"5","country":"USA","state":"CA","name":"University of California, Davis","subteam":""},{"id":"6","country":"USA","state":"CA","name":"San Francisco State University","subteam":""},{"id":"7","country":"USA","state":"CA","name":"Lassen Community College","subteam":""},{"id":"8","country":"USA","state":"CA","name":"Menlo College","subteam":""},{"id":"9","country":"USA","state":"CA","name":"Fresno Pacific University","subteam":""},{"id":"10","country":"USA","state":"CA","name":"Bakersfield","subteam":""},{"id":"11","country":"USA","state":"CA","name":"Buchanan","subteam":""},{"id":"12","country":"USA","state":"CA","name":"Campolindo-Moraga","subteam":""},{"id":"13","country":"USA","state":"CA","name":"Fremont-Sunnyvale","subteam":""},{"id":"14","country":"USA","state":"CA","name":"Ponderosa-Shingle Springs","subteam":""},{"id":"15","country":"USA","state":"CA","name":"West Covina","subteam":""},{"id":"16","country":"USA","state":"CA","name":"Gilroy","subteam":""},{"id":"17","country":"USA","state":"CA","name":"San José State University","subteam":""},{"id":"18","country":"USA","state":"CA","name":"University of California, …Run Code Online (Sandbox Code Playgroud) 我在一个主要是单线程,单用户的应用程序中工作.这里和那里有一些工作线程,它们只使用线程安全对象和类.单元测试实际上是测试具有多个线程的那些(为测试明确创建),并且它们测试正常.
在测试非线程安全的业务对象和子系统时,VSTS单元测试失败.它们可以不是线程安全的,这就是应用程序使用它们的方式.
但是,每个TestMethod的"一个线程"的MS测试方法会让我们失望.我必须在许多单元测试类中实现对象锁,只是为了确保测试一个接一个地运行(我真的不关心顺序,但是我不能让两个测试方法在同一个对象上运行同一时间).
代码如下所示:
[TestClass]
public class TestSomeObject
{
static object turnStile = new object();
...
[TestMethod]
public void T01_TestThis()
{
lock(turnStile)
{
.. actual test code
}
}
[TestMethod]
public void T02_TestThat()
{
lock(turnStile)
{
-- actual test code
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有更好/更优雅的方式使测试顺序进行?
我有以下WCF客户端配置:
<basicHttpBinding>
<binding name="basicHttpOCCWS" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="100000000" maxBufferPoolSize="524288"
maxReceivedMessageSize="100000000" messageEncoding="Text"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
在代码中,我按如下方式设置用户名和密码:
client.ClientCredentials.UserName.UserName = _cacledUserId;
client.ClientCredentials.UserName.Password = _cachedPassword;
Run Code Online (Sandbox Code Playgroud)
但是,在Tomcat上运行的Web服务返回错误:
"在安全上下文中找不到身份验证对象."
当我查看HTTP标头时,它缺少凭据信息,如下所示:
POST /occ600webservice/services/OCC_WS HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action=""
Host: 192.54.173.130:8080
Content-Length: 2223
Expect: 100-continue
Run Code Online (Sandbox Code Playgroud)
为什么我的凭据没有被发送?
TIA.
克劳斯
假设我有两种方法bool Foo()和bool Bar().以下哪项更具可读性?
if(Foo())
{
SomeProperty = Bar();
}
else
{
SomeProperty = false;
}
Run Code Online (Sandbox Code Playgroud)
要么
SomeProperty = Foo() && Bar();
Run Code Online (Sandbox Code Playgroud)
一方面,我认为短路&&是一个有用的功能,第二个代码样本要短得多.另一方面,我不确定人们通常习惯于&&在条件陈述之外看到,所以我想知道是否会引入一些认知失调,这使得第一个样本成为更好的选择.
你怎么看?还有其他影响决策的因素吗?比如,如果&&表达式长于可以放在屏幕上的一行,我应该更喜欢前者吗?
答案后澄清:
我应该把一些事情包括在答案提出的最初问题中.
Bar()可能比执行起来更昂贵Foo(),但这两种方法都不应该有副作用.Foo()归结为类似CurrentUserAllowedToDoX()和Bar()更像是,XCanBeDone()我只是对我的Zthes格式反序列化器(System.Xml.Serialization)进行最后润色,它使用元素"thes"中的命名空间"dc".所有"term"元素都是反序列化的,因为它们没有命名空间,但我无法弄清楚如何告诉反序列化器"thes"元素有一个命名空间.
这是我想要做的事情(这是行不通的)所以希望有人可以给我正确的语法.
[XmlElement("namespace:someElement")]
public string SomeElement;
Run Code Online (Sandbox Code Playgroud) CvPoint2D32f
Run Code Online (Sandbox Code Playgroud)
我想知道这个函数的作用,例如:
CvPoint2D32f center = cvPoint2D32f(src->width/2,src->height/2);
Run Code Online (Sandbox Code Playgroud) 我听说C++和Python是两种最常用的语言.
我应该选择哪一个?
在Python中 - 版本2或3?
我正在研究基本的游戏开发(例如赛车游戏)和非Flash/iphone /浏览器游戏.
我也不想跳到C#.
C++ vs python是我正在考虑的......
另外,如果您能让我知道一些在线资源,那将会很有帮助.
我有以下代码:
using (SqlConnection sqlConnection = new SqlConnection("blahblah;Asynchronous Processing=true;")
{
using (SqlCommand command = new SqlCommand("someProcedureName", sqlConnection))
{
sqlConnection.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@param1", param1);
command.BeginExecuteNonQuery();
}
}
Run Code Online (Sandbox Code Playgroud)
我从不调用EndExecuteNonQuery.
两个问题,首先是因为使用声明还是其他任何原因阻止了这个问题?第二,它会破坏什么吗?像泄漏或连接问题?我只是想告诉sql server运行一个存储过程,但我不想等待它,我甚至不关心它是否有效.那可能吗?谢谢阅读.
我在数据框中有以下变量:
[1] "Type" "I.alt" "idx06" "idx07" "idx08" "farve1" "farve2"
Run Code Online (Sandbox Code Playgroud)
如果我做:
dm <- melt(d, id=c("Type","I.alt"))
Run Code Online (Sandbox Code Playgroud)
我得到这些变量:
"Type" "I.alt" "variable" "value"
Run Code Online (Sandbox Code Playgroud)
其中"idx06","idx07","idx08","farve1","farve2"以"变量"表示.
但我真正想要的是这样的:
"Type" "I.alt" "variable" "value" "variable2" "value2"
Run Code Online (Sandbox Code Playgroud)
其中"farve1"和"farve2"表示在variable2和value2中.
我想要这样做的原因是,我想要的是,如果值下降则线条颜色为绿色,如果上升则为红色. 编辑:Shane已经展示了如何通过融合的两个融合来重塑数据.但是我的策略从一开始就构思错误 - 用一句话说错了.请参阅我对Shane解决方案的评论.
ggplot(dm, aes(x=variable,y=value,group=Type,col=variable2, label=Type,size=I.alt))+
geom_line()+
geom_text(data=subset(dm, variable=="idx08"),hjust=-0.2, size=2.5)+
theme_bw()+
scale_x_discrete(expand=c(0,1))+
opts(legend.position="none")
Run Code Online (Sandbox Code Playgroud)
我想我需要铸造熔化的框架 - 但我无法弄明白.数据:
d <- structure(list(Type = structure(c(8L, 21L, 23L, 20L, 6L, 14L,
3L, 24L, 2L, 28L, 32L, 22L, 15L, 29L, 1L, 17L, 18L, 33L, 25L,
13L, 30L, 11L, 26L, 9L, 12L, 4L, 5L, 27L, 16L, 19L, 10L, …Run Code Online (Sandbox Code Playgroud)