相关疑难解决方法(0)

ES-head插件无法通过浏览器工作

我正在尝试在我的服务器上运行elasticSearch-head插件,但我只能通过服务器终端访问它.如果我尝试通过浏览器访问它,它会尝试连接,直到显示"此页面不可用"浏览器消息.

如果我输入"curl -v http://localhost:9200/_plugin/head/"终端,我明白了

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9200 (#0)
> GET /_plugin/head/ HTTP/1.1
> User-Agent: curl/7.36.0
> Host: localhost:9200
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Content-Length: 1077
<
<!DOCTYPE html>

<html>
        <head>
                <meta charset="UTF-8">
                <title>elasticsearch-head</title>
                <link rel="stylesheet" href="dist/base/reset.css">
                <link rel="stylesheet" href="dist/vendor.css">
                <link rel="stylesheet" href="dist/app.css">
                <script src="dist/i18n.js" data-baseDir="dist/lang" data-langs="en,fr,pt"></script>
                <script src="dist/vendor.js"></script>
                <script src="dist/app.js"></script>
                <script>
                        window.onload = function() {
                                if(location.href.contains("/_plugin/")) {
                                        var base_uri = location.href.replace(/_plugin\/.*/, '');
                                }
                                var …
Run Code Online (Sandbox Code Playgroud)

plugins frontend head elasticsearch

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

当我可以从PHP发出请求时,为什么Ajax会给我一个交叉起源错误?

我可以从PHP发出GET请求并获得正确的响应.这是我使用的功能:

PHP

function httpGet($url)
{
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false);

    $output=curl_exec($ch);
    curl_close($ch);
    return $output;
}
Run Code Online (Sandbox Code Playgroud)

一个简单的例子:

$fakevalue='iamfake';
$url="http://fakeurl.com?fakeparameter=".$fakevalue;
$jsondata= httpGet($url);
$fake_array = json_decode($jsondata, true);
$weed_var=$fake_array['weeds']; // successfully obtained weed.
Run Code Online (Sandbox Code Playgroud)

此函数返回服务器的响应.

现在我在AJAX中尝试相同的HTTP GET请求,但我无法得到响应.

最初我认为问题出在我使用的JavaScript函数上.Google为我提供了许多用于执行HTTP GET请求的JavaScript函数,但它们都有同样的问题.请求返回错误而不是我使用PHP时获得的数据.

JAVASCRIPT

var fakevalue = "iamfake";

var fake_data = {
    fakeparameter: fakevalue
};

$.ajax({
    url: "http://fakeurl.com",
    data: fake_data,
    type: "GET",
    crossDomain: true,
    dataType: "json",
    success: function(a) {
        $("#getcentre").html(a);
    },
    error: function() {
        alert("Failed!");
    }
});
Run Code Online (Sandbox Code Playgroud)

来自JavaScript的错误

XMLHttpRequest cannot load http://fakeurl.com?fakeparameter=fakevalue. No 'Access-Control-Allow-Origin' header is present …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax jquery get

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

Android WebView"No'Access-Control-Allow-Origin'标头出现在请求的资源上"

我正在尝试加载测试网页(在我的服务器中).页面是:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>

<iframe width="420" height="315" src="http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1"/>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是webView没有加载页面.甚至没有onProgressChanged在%40-50之后调用

此外,从url加载js脚本的所有站点都会出现此问题.包括youtube,fb等.

WebConsole: XMLHttpRequest cannot load https://googleads.g.doubleclick.net/pagead/id. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.youtube.com' is therefore not allowed access. 
Run Code Online (Sandbox Code Playgroud)

在这里我的设置

    FrameLayout contentFrame = (FrameLayout) findViewById(R.id.ContentFrame);
    WebView mWebView = new WebView(this);

    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    mWebView.getSettings().setAllowFileAccessFromFileURLs(true);

    mWebView.loadUrl("http://ozgur.dk/browser.html");

    contentFrame.removeAllViews();
    contentFrame.addView(mWebView);
Run Code Online (Sandbox Code Playgroud)

布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@+id/ContentFrame"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
Run Code Online (Sandbox Code Playgroud)

android webview

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

获取请求成功完成,但响应对象为空

我在componentDidMount()React 组件的方法中有一个 fetch 请求:

const request = new Request(url, {
    mode: 'no-cors',
    method: 'get',
    headers: {
        Accept: 'application/json'
    }
});

fetch(request)
    .then(function(response) {  
        console.log('Response: ', response);

        return response.text();  
    })
    .then(function(data) {
        // _this.setState({ data: data });

        console.log('Success: ', data);
        console.log('Request succeeded with JSON response', data);
    }).catch(function(error) {
        console.log('Request failed', error);
    });
Run Code Online (Sandbox Code Playgroud)

当组件加载时,我可以看到在控制台中发出请求并返回正确的数据;但是,我的 Response 对象始终为空:

Response { type: "opaque", url: "", redirected: false, status: 0, ok: false, statusText: "", headers: Headers, bodyUsed: false }
Run Code Online (Sandbox Code Playgroud)

response.text()返回 null,我真的不确定发生了什么。我之前也用过同样的方法,没有出现过这个问题,所以不确定是第三方数据源的原因还是什么的不一样。

有任何想法吗?

javascript response fetch reactjs fetch-api

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

当我使用 ng build 时,proxy.config.json 在 Angular 4/5 中不起作用

我正在使用代理 api 设置来进行 angular 5 中的 API 调用,如本网站所述。https://juristr.com/blog/2016/11/configure-proxy-api-angular-cli/ 当我使用 npm start 时,这可以正常工作。但是当我构建它并将其托管在 IIS 上时。它不工作。我相信 proxy.config.json 没有添加到 dist 文件夹中。

build angular

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

Angular 客户端启用 CORS

CORS 在服务器上很好,并且按预期工作。我尝试使用 angular HTTPClient 向服务器的 REST API 发送请求,但收到 CORS 错误。如果在服务器上启用了 CORS,为什么会出现此错误?客户端应该没问题吧?

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/api/blah/blah (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Run Code Online (Sandbox Code Playgroud)

我怎样才能在这个请求上启用 CORS..... 在此处输入图片说明

node.js cors express angular

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

无法从多个 html 输入字段中添加或删除图像

我使用https://github.com/promosis/file-upload-with-preview来显示多张图片的预览

var upload = new FileUploadWithPreview('myUniqueUploadId', {
  maxFileCount: 4,
  text: {
    chooseFile: 'Maximum 4 Images Allowed',
    browse: 'Add More Images',
    selectedCount: 'Files Added',
  },
});
Run Code Online (Sandbox Code Playgroud)
.custom-file-container {
  max-width: 400px;
  margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://unpkg.com/file-upload-with-preview@4.0.2/dist/file-upload-with-preview.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/file-upload-with-preview@4.0.8/dist/file-upload-with-preview.min.js"></script>
<form action="save.php" method="post" enctype="multipart/form-data">
  <div class="custom-file-container" data-upload-id="myUniqueUploadId">
    <label>Upload File <a href="javascript:void(0)" class="custom-file-container__image-clear" title="Clear Image">&times;</a></label>
    <label class="custom-file-container__custom-file">
                    <input type="file" name="files[]" class="custom-file-container__custom-file__custom-file-input" accept="image/*" multiple aria-label="Choose File">
                    <input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
                    <span class="custom-file-container__custom-file__custom-file-control"></span>
                </label>
    <div class="custom-file-container__image-preview" style="overflow: auto!important"></div>
  </div>
  <input type="submit" value="Upload …
Run Code Online (Sandbox Code Playgroud)

html javascript image

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

Pocket API:如何获取Access令牌

我正在尝试制作一个网页,显示我在Pocket中存储的"Read it later"文章列表,使用他们的API,并按照他们的文档中发布的说明进行操作.

第1步:拥有一个消费者密钥.我创建了Pocket App,并拥有了consumer_key.

第2步:获取访问令牌.这是我被卡住的地方.我应该用consumer_key和我发送一个POST请求redirect_uri,我不明白.我的脚本位于domain.com/pocket/index.php,这是我想要发送令牌的地方,所以我假设redirect_uri是那个url.但是在文档中,他们使用类似" pocketapp12388:authorizationFinished"的东西,这看起来不像我的网址.

在任何情况下,无论我使用哪个,我都会收到"400 Bad Request",这意味着redirect_uri不正确.我究竟做错了什么?

这是jsfiddle.net上的一个小型演示

php api jquery pocket

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

如何在纯js上编写JSONP Ajax请求?

$.ajax( { url : '', data: {}, dataType:'jsonp',  jsonpCallback: 'callbackName', type: 'post'
        ,success:function (data) {
        console.log('ok');
        },
        error:function () {
        console.log('error');
        }
        });
Run Code Online (Sandbox Code Playgroud)

如何在纯JS中编写相同的功能?

javascript ajax jsonp

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

使用Fetch API下载图片

我知道这个问题已经解决,但是使用Fetch API下载图片时遇到问题。
我用来获取图像的代码。

function downloadImage() {
  fetch('https://upload.wikimedia.org/wikipedia/commons/9/98/Pet_dog_fetching_sticks_in_Wales-3April2010.jpg',
    {mode: 'no-cors'})
  .then(response => response.blob())
  .then(blob => {
        console.log(blob);           
  });
}
Run Code Online (Sandbox Code Playgroud)

在这里,console.log我得到回应Blob {size: 0, type: ""}
请让我知道我在这里做错了吗?

javascript fetch-api

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