Wordpress 电话号码';访问控制允许原点';请求的资源上存在标头
我正在创建一个基本的phonegap应用程序,它由wordpress网站提供支持 每次我使用正确的详细信息处理以下内容时,都会出现以下错误:Wordpress 电话号码';访问控制允许原点';请求的资源上存在标头,wordpress,cordova,phonegap-desktop-app,Wordpress,Cordova,Phonegap Desktop App,我正在创建一个基本的phonegap应用程序,它由wordpress网站提供支持 每次我使用正确的详细信息处理以下内容时,都会出现以下错误: XMLHttpRequest cannot load http://example.com?action=login&username=user&password=password. No 'Access-Control-Allow-Origin' header is present on the requested resource. O
XMLHttpRequest cannot load http://example.com?action=login&username=user&password=password. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
这是我的密码:
function fetch_and_display_posts()
{
var xhr = new XMLHttpRequest();
xhr.open("GET", "myurlhere");
xhr.onload = function(){
var posts_array = JSON.parse(xhr.responseText);
var html = "";
for(var count = 0; count < posts_array.length; count++)
{
var title = posts_array[count][0];
var link = posts_array[count][1];
var date = posts_array[count][2];
var image = posts_array[count][3];
html = html + "<li>" + "<a href='javascript:open_browser(\"" + link + "\")'>" + "<img height='128' width='128' src='" + image + "'>" + "<h2>" + title + "</h2>" + "<p>" + date + "</p></a></li>";
}
document.getElementById("posts").innerHTML = html;
$("#posts").listview("refresh");
}
xhr.send();
}
function login()
{
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if(username == "")
{
navigator.notification.alert("Please enter username", null, "Username Missing", "OK");
return;
}
if(password == "")
{
navigator.notification.alert("Please enter password", null, "Password Missing", "OK");
return;
}
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://example.com?action=login&username=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password));
xhr.onload = function(){
if(xhr.responseText == "FALSE")
{
navigator.notification.alert("Wrong Username and Password", null, "Wrong Creds", "Try Again");
}
else if(xhr.responseText == "TRUE")
{
fetch_and_display_posts();
$("#page_two_link").click();
}
}
xhr.send();
}
function open_browser(link)
{
window.open(link, '_blank', 'location=yes');
}
函数获取和显示帖子()
{
var xhr=new XMLHttpRequest();
xhr.open(“GET”,“myurlhere”);
xhr.onload=函数(){
var posts_array=JSON.parse(xhr.responseText);
var html=“”;
对于(var count=0;count”+“”;
}
document.getElementById(“posts”).innerHTML=html;
$(“#posts”)。列表视图(“刷新”);
}
xhr.send();
}
函数登录()
{
var username=document.getElementById(“用户名”).value;
var password=document.getElementById(“密码”).value;
如果(用户名==“”)
{
navigator.notification.alert(“请输入用户名”,null,“用户名丢失”,“确定”);
返回;
}
如果(密码==“”)
{
navigator.notification.alert(“请输入密码”,null,“密码丢失”,“确定”);
返回;
}
var xhr=new XMLHttpRequest();
xhr.open(“GET”http://example.com?action=login&username=“+encodeURIComponent(username)+”&password=“+encodeURIComponent(password));
xhr.onload=函数(){
如果(xhr.responseText==“FALSE”)
{
navigator.notification.alert(“错误的用户名和密码”、null、“错误的凭据”、“重试”);
}
else if(xhr.responseText==“TRUE”)
{
获取和显示帖子();
$(“第二页链接”)。单击();
}
}
xhr.send();
}
功能打开浏览器(链接)
{
打开(链接“_blank”,“location=yes”);
}
我如何解决这个问题?我认为这与跨域安全有关?看起来您有CORS问题 打开服务器端代码,并在脚本顶部显示以下内容
header("Access-Control-Allow-Origin: *");