How to resolve net::ERR_CONNECTION_REFUSED - google-chrome

I am trying to do a GET request to my server. I have done it many times previously, and everything was working.
But now, when I launch it on Google Chrome, it gives me this error :
GET http://myserver.net:443/searchShoplist/apple net::ERR_CONNECTION_REFUSED
When I launch it on Firefox, I have no result and no response.
Here is the code of my request to the server :
var data = null;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "http://myserver.net:443/searchShoplist/apple");
xhr.send(data);

Related

Adding a query to a HTML Page

I have built a Status Page for my servers with HTML and CSS, and instead of updating the Server Status every time one of them goes down, I was wondering if it's possible to add something to query the IP's of the server every 10m or so, and if the query fails, to turn the status button to RED.
Here's what I'm working with: https://status.floridastaterp.org
Any help is largely appreciated!
Thanks.
You can do it without PHP, for that use javascript and make a ajax call:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// You change the status of button
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
And to call it every 10min, warp your function with:
setTimeout(request(),1000);
function request(){
if(response == true){
// This makes it unable to send a new request
// unless you get response from last request
response = false;
var req = $.ajax({
type:"post",
url:"https://status.floridastaterp.org"
});
req.done(function(){
console.log("Request successful!");
// This makes it able to send new request on the next interval
response = true;
});
}
setTimeout(request(),1000);
}
request();

replace 'GET' url with a variable

Ive searched for this topic and ended here https://stackoverflow.com/search?q=api+replace+%27GET%27+url+with+a+variable yet no answer seems to addres my question.
this is my code:
function wpp(){
let ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'https://averylong.url/with/some/stuff/andshit'); <-- wan to to replace this with a variable
ourRequest.onload = function() {
if (ourRequest.status >= 200 && ourRequest.status < 400) {
let data = JSON.parse(ourRequest.responseText);
myHtml(data);
} else {
console.log("server returned an error.");
}
};
ourRequest.onerror = function() {
console.log("Connection error");
};
ourRequest.send();
}
what I want to do is the following
let myNewUrl = localStorage.getItem(449);
function wpp(){
let ourRequest = new XMLHttpRequest();
ourRequest.open('GET', myNewUrl);
ourRequest.onload = function() {
if (ourRequest.status >= 200 && ourRequest.status < 400) {
let data = JSON.parse(ourRequest.responseText);
myHtml(data);
} else {
console.log("server returned an error.");
}
};
ourRequest.onerror = function() {
console.log("Connection error");
};
ourRequest.send();
}
But every time I get this error:
GET https://averylong.url/with/some/stuff/449 403 (Forbidden)
but if I copy/paste the very same url in my browswer I get back the json data no problem
EDIT screenshot
console error
I want to thank #ravi his comment lead me way down in to the rabbit hole..... Some things can not being unseen, but I found the answer somewhere.
The problem was ModSecurity it happends that ModSecurity does not like wordpress and you have to disable it or it will return a 403 error, now the funny part is that even when it return a 403 error it will display the results on the 'browser' and 'Postman' and that is why I tought I was writing wrong javascript, it happends that when javascript finds the 403 error just stops and wont render the answer even if it's there. Solution: turn off ModSecurity if you are working with wordpress API.

API errors on Google Apps Script

I created a POST function to Harvest using postman and it was successful, I exported the code in as javascript but then when I go to run it in the google apps script I get, ‘ReferenceError: “FormData” is not defined.’
Any idea what this is referring too?
function myFunction() {
var data = new FormData();
data.append(“name”, “TEST_CLIENT”);
data.append(“is_active”, “true”);
data.append(“address”, “”);
data.append(“currency”, “USD”);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener(“readystatechange”, function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open(“POST”, “https://api.harvestapp.com/v2/clients?
name=TEST_CLIENT&is_active=true&address=1%20Main%20st.%20&currency=USD”);
xhr.setRequestHeader(“Authorization”, “Bearer {{$ACCESS_TOKEN}}”);
xhr.setRequestHeader(“Harvest-Account-Id”, “{{$ACCOUNT_ID}}”);
xhr.setRequestHeader(“User-Agent”, “(hidden)”);
xhr.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
xhr.setRequestHeader(“Cache-Control”, “no-cache”);
xhr.setRequestHeader(“Postman-Token”, “HIDDEN”);
xhr.send(data);
}
I hid some parts of my code

console logs 'The provider id_provider is not a valid one'

Trying to get head around when debugging a Viewer app. Chrome console shows 'The provider id_provider is not a valid one'. Any suggestion?
If options is like this:
var options = {
env: 'AutodeskProduction',
getAccessToken: getToken }
}
function getToken () {
var response;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
response = JSON.parse(
xhr.responseText);
return response.access_token;
}
if forcing 2.9, 'The provider id_provider is not a valid one'.
If forcing 2.7 or 2.8, not log but the viewer doesn't show up.
If no specified version, 'Warning : no access token is provided. Use built in token : YtTb8vRA4XQfTorjm9c8eVZJTYP6'.
it stops in Autodesk360App.js
var initialItem = app.getDefaultGeometry(geometryItems);
Chrome logs 'Uncaught TypeError: app.getDefaultGeometry is not a function'
If I directly feed token:
accessToken: 'MorPwhKARIS3VGIrcd3FrZSjsnOx5'
it works beautifully in 2.7,2.8 and 2.9. But if no version, it stops in Autodesk360App.js, the same as above.
Thank you!
Aren't you missing the url on the http request? Maybe something line:
function getToken() {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", '/yourTokenEndPoint', false);
xmlHttp.send(null);
var response = JSON.parse(xmlHttp.responseText);
return response.access_token;
}
For the Viewer, it must be synchronous.

how to send json data to server in cordova android

hi frnd form last 2 days i am trying to send JSON data to server but is not working i am posting my js file and check if any error. and i am try to send json data by using xmlHttprequest. and if any other function and any change i have to do then plz tell me. i am developing cordova project in eclipse.and if any other thing and any file also have to change then tell me
this is my js file and on click registration button i am calling this method.
function get() {
alert("function is called");
var name_field_value=document.getElementById("name_field").value;
var email_field_value=document.getElementById("email_field").value;
var password_field_value=document.getElementById("password_field").value;
var phone_field_value=document.getElementById("phone_field").value;
var JSONdata= {
"name": name_field_value,
"mobile_number": phone_field_value,
"email": email_field_value,
"password": password_field_value
}
var request = new XMLHttpRequest();
request.open("POST", "http://www.jiyonatural.com/AccountManagements/insert_new_user", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
alert(request.status);//this alert is working and getting 0 status
if (request.status == 200 || request.status == 0) {
// -> request.responseText <- is a result
/*var tweets = JSON.parse(request.responseText);*/
alert(request.responseText);//this alert is not working//
//if i make other alert then it works
}else{
alert("function is called3");}
}
}
request.send(JSON.stringify(JSONdata));
}
Looks like your question is incomplete.
In my experience the error probably lies in server code friend.
And you should use ajax method in jquery for communication with server.its easier than XMLhttpRequest.