0
전 브라우저 확장 기능이 완전히 새롭습니다. 웹 페이지 콘텐츠를 자동으로 변경하는 간단한 확장 프로그램을 만들었지 만 이제 서버에 true 또는 false 값을 쿼리 한 후 해당 콘텐츠를 변경하려고합니다. 나는 AJAX 요청 (순수한 자바 스크립트)로 이것을하려고한다. 어떤 이유로 든 브라우저 확장이 상호 작용하는 서버의 PHP 스크립트에서 정보를 얻을 수 없습니다.Firefox 확장 프로그램에서 AJAX 요청을하는 방법은 무엇입니까?
매니페스트 :
{
"manifest_version": 2,
"name": "Truth Seeker",
"version": "1.0",
"description": "Returns true.",
"icons": {
"48": "icons/icon.png"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["script.js"]
}
]
}
스크립트 :
theBool = false;
url = /* PHP URL HERE */;
string = "";
request(MakeOutput, url, string);
if(theBool == true){
alert("is true");
}
function MakeOutput(x){
if(x == "true"){
theBool = true;
}
}
function request(fix, url, string){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
fix(xhttp.responseText);
}
}
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(string);
}
순간에 바로 에코 "true"로 서버에있는 PHP 파일. 브라우저에 URL을 입력하여 PHP 스크립트에 직접 액세스하면 "사실입니다"라는 경고를 표시합니다. 왜 그렇게 할 것이나 다른 페이지는 없을 것입니다.