我正在尝试使用jquery发送请求并从另一个网站获得响应。请求已发送,我已经收到200。但是我无法从服务器收到响应消息,我看到evretime是该错误: (我在woocomerce中使用wordpress。我的管理员在bluehost上)
Execution time while using member function remove: 121
Execution time while using generic algorithm remove: 125
Process finished with exit code 0
这是我的标题:
#include <list>
#include <algorithm>
#include <chrono>
#include <iostream>
using namespace std;
int main()
{
srand(time(nullptr));
list<int>my_list1;
// list<int>my_list2;
int x = 2000 * 2000;
for (auto i = 0; i < x; ++i)
{
auto random = rand() % 10;
// my_list1.push_back(random); // avoid pushing to front and back to avoid cache misses.
my_list1.push_front(random);
}
list<int>my_list2(my_list1);
auto started1 = std::chrono::high_resolution_clock::now();
my_list1.remove(5);
auto done1 = std::chrono::high_resolution_clock::now();
cout << "Execution time while using member function remove: " << chrono::duration_cast<chrono::milliseconds>(done1 - started1).count();
cout << endl << endl;
auto started2 = std::chrono::high_resolution_clock::now();
my_list2.erase(remove(my_list2.begin(), my_list2.end(),5), my_list2.end());
auto done2 = std::chrono::high_resolution_clock::now();
cout << "Execution time while using generic algorithm erase: " << chrono::duration_cast<chrono::milliseconds>(done2 - started2).count();
cout << endl << endl;
}
还有我的请求API函数
Failed to load https://smm.nakrutka.by/api/?key=76856&action=create&service=34&quantity=100&link=https://www.instagram.com/p/BnWW4npDAU5/: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://fejmu.pl' is therefore not allowed access.
scripts.js:259 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://smm.nakrutka.by/api/?key=3262a5221b2643d925fcd5752d021b2f&action=create&service=34&quantity=100&link=https://www.instagram.com/p/BnWW4npDAU5/ with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
(anonymous) @ scripts.js:259
sentOrderAPIRequest @ scripts.js:243
Promise.then (async)
(anonymous) @ scripts.js:40
dispatch @ jquery-1.11.2.min.js:3
r.handle @ jquery-1.11.2.min.js:3
答案 0 :(得分:-1)
您不需要CORS。
您可以在自己的网站上调用代理脚本,然后使用cURL或Guzzle从PHP进行调用。这就是我一直这样做的方式。
jQuery:
$.get('/your/proxy/url.php', {any: "vars", go: "here"}, function(data){
console.log(data);
});
php:
<?php
$data = file_get_contents('the url you are calling from js here');
header('Content-Type: application/javascript'); // if $data is JSON
echo $data;
exit;