小编Tho*_*yme的帖子

使用Jquery从本地文件中获取JSON对象

我正在尝试使用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)

基于此示例:http://api.jquery.com/jQuery.getJSON/

javascript jquery json local-files

12
推荐指数
1
解决办法
4万
查看次数

使用JavaScript崩溃firefox

我是测试团队的一员,并且在Firefox浏览器中使用JavaScript负责"表现糟糕".我已经尝试过这些方法来关闭浏览器,但是他们都没有做任何比导致弹出窗口要求关闭脚本更糟糕的事情.

还有其他想法吗?

javascript security firefox

7
推荐指数
2
解决办法
1万
查看次数

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

无法让我的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 …

c# wcf jquery post httpwebrequest

7
推荐指数
1
解决办法
2万
查看次数

模拟退格按钮在c#中使用null ActiveSource

背景:我们在触摸屏信息亭上使用屏幕键盘,允许用户输入文字.退格按钮失败,因为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}")也不起作用.

c# keyboard-events uikeyboard

2
推荐指数
1
解决办法
3427
查看次数

静态常量自定义类

我正在尝试创建一个自定义类的常量静态集合,如下所示:

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对象的常量静态类?

c# static initialization const

2
推荐指数
2
解决办法
4793
查看次数

Java Mockito和代表团

每次调用getLastModifiedDate时我都需要返回新的Date().我正在使用这个模拟:

when(network.getLastModifiedDateOf(any(URL.class))).
            thenReturn(formatDate(new Date()));
Run Code Online (Sandbox Code Playgroud)

但是,每次调用getLastModifiedDateOf时,它都会返回测试开始时的相同日期/时间.我想我需要像C#委托这样的东西,每次模拟被击中时调用新的Date().

java delegates mockito

1
推荐指数
1
解决办法
2819
查看次数