我正在尝试使用Jquery从本地文件中获取JSON对象(产品)列表,并将所有对象存储在名为allItems的单个数组中.该文件与代码位于同一目录中,并称为"allItems.json".我现在就是这样做的:
function getAllSupportedItems(){
var allItems = new Array();
$.getJSON("allItems.json",
function(data){
$.each(data.items,
function(item){
allItems.push(item);
});
});
return allItems;
}
Run Code Online (Sandbox Code Playgroud)
我是测试团队的一员,并且在Firefox浏览器中使用JavaScript负责"表现糟糕".我已经尝试过这些方法来关闭浏览器,但是他们都没有做任何比导致弹出窗口要求关闭脚本更糟糕的事情.
还有其他想法吗?
无法让我的JQuery POST被WCF服务接受.这是来自javascript的POST:
function jqueryPost() {
var url = "/LoggingTest";
$.post(url, { message: "test message" });
}
Run Code Online (Sandbox Code Playgroud)
这是我通过接口接受POST的方式:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/LoggingTest",
BodyStyle = WebMessageBodyStyle.Bare)]
void LoggingTest(string message);
Run Code Online (Sandbox Code Playgroud)
并实施:
public void LoggingTest(string message)
{
log.Debug(message, null);
}
Run Code Online (Sandbox Code Playgroud)
当我调用函数jqueryPost时,我在Web检查器中看到了400 Bad Request的HTTP响应.不确定如何让POST请求工作.
(在7/1上添加)
@James,这是web检查器的输出:
http:// localhost:4252/LoggingTest HTTP信息
请求方法:POST
状态码:400错误请求
请求标头
接受:/
Cache-Control:max-age = 0
内容类型:application/x-www-form-urlencoded
原产地:http:// localhost:4252
Referer:http:// localhost:4252 /
User-Agent:Mozilla/5.0(Windows; U; Windows NT 5.1; C - )AppleWebKit/532.4(KHTML,如Gecko)Qt/4.6.2 Safari/532.4
X-Requested-With:XMLHttpRequest
表单数据
消息:测试消息
响应标头
内容长度:1165
内容类型:text/html …
背景:我们在触摸屏信息亭上使用屏幕键盘,允许用户输入文字.退格按钮失败,因为System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource变为null.
代码上下文:
if (System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource != null)
{
System.Windows.Input.KeyEventArgs ke =
new System.Windows.Input.KeyEventArgs(
System.Windows.Input.Keyboard.PrimaryDevice,
System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource,
0,
System.Windows.Input.Key.Back);
ke.RoutedEvent = UIElement.KeyDownEvent;
System.Windows.Input.InputManager.Current.ProcessInput(ke);
}
else
{
Console.Out.WriteLine("Problemo");
}
Run Code Online (Sandbox Code Playgroud)
我不能使用具有null ActiveSource的KeyEventArgs,并且System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}")也不起作用.
我正在尝试创建一个自定义类的常量静态集合,如下所示:
public class MyClass
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后创建一类MyClass的常量静态对象
static class MyObjects
{
public const MyClass anInstanceOfMyClass = { Property1 = "foo", Property2 = "bar" };
}
Run Code Online (Sandbox Code Playgroud)
但是编译器抱怨在当前上下文中不存在名称"Property1"和"Property2".当我这样做时:
public const MyClass anInstanceOfMyClass = new MyClass() { Property1 = "foo", Property2 = "bar" };
Run Code Online (Sandbox Code Playgroud)
编译器抱怨Property1和Property2是只读的.如何正确初始化这些MyClass对象的常量静态类?
每次调用getLastModifiedDate时我都需要返回新的Date().我正在使用这个模拟:
when(network.getLastModifiedDateOf(any(URL.class))).
thenReturn(formatDate(new Date()));
Run Code Online (Sandbox Code Playgroud)
但是,每次调用getLastModifiedDateOf时,它都会返回测试开始时的相同日期/时间.我想我需要像C#委托这样的东西,每次模拟被击中时调用新的Date().
c# ×3
javascript ×2
jquery ×2
const ×1
delegates ×1
firefox ×1
java ×1
json ×1
local-files ×1
mockito ×1
post ×1
security ×1
static ×1
uikeyboard ×1
wcf ×1