小编JSN*_*nja的帖子

向logstash发出发布请求时发生CORS错误

我已将Logstash 1.5.2配置为使用Linux计算机上的http输入。

这是我的logstash输入配置:

input {
        http {
                host => "10.x.x.120"
                port => "8500"
        }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用linux机器上的curl -XPOST将数据发送到logstash。

但是当我做一个$ http.post(url,postData); 来自angularJS应用程序的请求,出现以下错误:

跨域请求被阻止:同源策略禁止读取远程资源

我已经在docker容器中使用nginx将应用程序托管在同一台Linux计算机上。我试图通过将以下行添加到nginx.conf来配置nginx以允许CORS:

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
Run Code Online (Sandbox Code Playgroud)

但是错误仍然存​​在。

同样,当我从浏览器地址栏中点击http://10.xx120:8500时,我也得到了“确定”。

在此处输入图片说明 在此处输入图片说明 非常感谢您的帮助。谢谢。

linux http nginx cors angularjs

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

maxlength在cordova android app中的输入类型文本中不起作用

我正在尝试在android cordova 3.5.0应用程序中实现一个输入字段,如下所示:

<input type="text" maxlength="7" class="form-control" placeholder=" "/>
Run Code Online (Sandbox Code Playgroud)

但是maxlength根本不起作用.

我尝试使用javascript如下工作:

function checkTestPressure(txtBox){

    if(txtBox.value.length > 7){
    console.log(" txtBox = "+ txtBox.value.length);
    var str = txtBox.value;
    str = str.substr(0,7);
    txtBox.value = str;
    }
}
Run Code Online (Sandbox Code Playgroud)

html如下:

<input type="text" maxlength="7" class="form-control" onkeyup="checkTestPressure(this);" onblur="trimWhiteSpacesForTextBox(this);"  id="testpressure" placeholder=" ">
Run Code Online (Sandbox Code Playgroud)

这首先工作,但如果我在7位数后继续点击键盘上的键,输入文本字段变空并开始重新填充,因为我一直按下键.

这是不可接受的,我只想要前7个字符,无论我按键盘上的键多少次都不应填充字段.

上面的代码在桌面上的浏览器中工作正常但在我在cordova android应用程序中运行时给出了上面提到的问题.

任何帮助表示赞赏.

提前致谢.

html javascript html5 android cordova

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

标签 统计

android ×1

angularjs ×1

cordova ×1

cors ×1

html ×1

html5 ×1

http ×1

javascript ×1

linux ×1

nginx ×1