我有一个小问题,我用网站helpscout创建的文档创建了一个wordpress主题,为了减少支持票证的数量,我想做同样的事情EDD:https://easydigitaldownloads.com/support/, 如果您单击“提交支持请求”,将显示一个输入,如果您输入一个单词,例如“google”,则可以使用指向helpscout文档的链接,然后您可以创建请求。我复制了这个网站的代码,我用重力表单创建了一个多部分表单,一切都很好,除了看文档,这是我输入的代码。php文件:
function support_form() {
if ( ! wp_script_is( \'gform_gravityforms\' ) ) {
return;
} ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var wrap = $(\'.gform_body .gfield.helpscout-docs\');
var paging = $(\'.gform_body .gform_page_footer\');
var hidden = $(\'.gform_body .gfield.helpscout-docs\').next().find(\'input\');
var field = wrap.find(\'input[type="text"]\');
var searching = false, allowed = false;
paging.hide();
wrap.append( \'<div class="docs-search-wrap"></div>\' );
field.attr( \'autocomplete\', \'off\' );
paging.find(\'input[type="submit"]\').on(\'click\', function(e) {
if( ! allowed ) {
return false;
}
});
field.keyup(function(e) {
query = $(this).val();
if( query.length < 4 ) {
return;
}
var html = \'<ul class="docs-search-results">\';
if( ! searching ) {
var count = 0;
// Getting Started
$.ajax({
url: \'https://docsapi.helpscout.net/v1/search/articles?collectionId=56d89d519033600eafd436e4&query=\' + query,
headers: {
\'Authorization\': \'Basic <?php echo base64_encode( \'username:password\' ); ?>\'
},
xhrFields: {
withCredentials: false
},
beforeSend: function() {
searching = true;
},
success: function(results) {
count += results.articles.items.length;
$.each( results.articles.items, function( key, article ) {
html = html + \'<li class="article"><a href="\' + article.url + \'" title="\' + article.preview + \'" target="_blank">\' + article.name + \'</a><li>\';
});
}
}).done(function() {
// FAQs
$.ajax({
url: \'https://docsapi.helpscout.net/v1/search/articles?collectionId=56d8b3c9c6979159b4453cf6&query=\' + query,
headers: {
\'Authorization\': \'Basic <?php echo base64_encode( \'username:password\' ); ?>\'
},
xhrFields: {
withCredentials: false
},
beforeSend: function() {
searching = true;
},
success: function(results) {
count += results.articles.items.length;
$.each( results.articles.items, function( key, article ) {
html = html + \'<li class="article"><a href="\' + article.url + \'" title="\' + article.preview + \'" target="_blank">\' + article.name + \'</a><li>\';
});
}
}).done(function() {
// Extensions
$.ajax({
url: \'https://docsapi.helpscout.net/v1/search/articles?collectionId=56d8b96fc6979159b4453d22&query=\' + query,
headers: {
\'Authorization\': \'Basic <?php echo base64_encode( \'username:password\' ); ?>\'
},
xhrFields: {
withCredentials: false
},
beforeSend: function() {
searching = true;
},
success: function(results) {
count += results.articles.items.length;
$.each( results.articles.items, function( key, article ) {
html = html + \'<li class="article"><a href="\' + article.url + \'" title="\' + article.preview + \'" target="_blank">\' + article.name + \'</a><li>\';
});
}
}).done(function() {
html = html + \'</ul>\'
html = \'<span class="results-found">\' + count + \' results found . . . </span>\' + html;
wrap.find(\'.docs-search-wrap\').html( html );
paging.show();
searching = false;
});
});
});
}
});
});
</script>
<?php
}
add_action( \'send_headers\', \'add_header_acao\' );
function add_header_acao() {
header( \'Access-Control-Allow-Origin: *\' );
}
但是,当我在输入中输入一个单词时,控制台中会收到一条错误消息:“请求的资源上不存在“Access Control Allow Origin”标头。”
我没有正确插入“Access Control Allow Origin”(访问控制允许原点)?是不是因为“用户名:密码”,我在仪表板帮助scout中设置了用户名和密码,也许我不需要插入。
你能帮帮我吗?
非常感谢:)