Using Ipinfo.io in Javascript - javascript

Okay, so, I'm trying to pull the correct region and city from Ipo.io but it isn't working. When ran locally it's giving me one location, which is wrong, and when deployed it also gives me a location but it's also wrong.
What I'm Trying To Do: pull the correct locations when user clicks a button.
The html is fine, so no need to add it. The js file where the request is looks like so (didn't include the whole file, just the relevant parts).
showMe is a modal that pops up once a user is scrolling the screen. Everything works fine the location is just wrong. I looked at the docs and it doesn't say anything about Javascript, so I'm writing to you guys in hopes that this tool actually works with Javascript.
Any help would be appreciated, thanks!
$('#showMe').click(() => {
$('#time-text').empty();
$.get("https://ipinfo.io?token=insert-token", function (response) {
$('#time-text').append(response.region);
}, "jsonp")
});
also, just to be clear, i've also tried this - as given in their documentation, but it throws an error.
$.get("https://ipinfo.io", function (response) {
$('#time-text').append(response.region);
}, "jsonp")
The error I am receiving for the last implemention is:
jquery-3.4.1.min.js:2 GET https://ipinfo.io/?callback=jQuery34105473588412770183_1578083636662&_=1578083636663 net::ERR_ABORTED 429
For the first implementation, there is no error - just wrong location.

You're getting a 429 Error, which means you've hit the request limit for the Day / Month (Depends)
Here is the relevant part of the the Docs discussing the Rate Limits

Related

Why does React log to Chrome-Console "Content-script injection failed" (from allpages.js) when I never set up code to inject a script?

I am nearly done with my code for my new Website but am really bothered that the following gets somehow logged to my Chrome-Console:
For instance, it gets printed when I switch between pages of my Website (using react-router-dom). I am not consciously injecting any script (nor do I know how that would work or why I would do such a thing).
I don't even know what "allpages.js" is, I never came across it so far.
If I click on it, to see the area that throws the error, I get the following (it is on line 83):
Happy to provide any further info or code and thanks everyone!

PWA Service Worker - Failed to fetch - Issue with Facebook Pixel

I have the following PWA Service Worker (serviceWorker.js):
self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => {
return res || fetch(fetchEvent.request)
})
)
})
I don't want anything to load when offline, because it's a fully dynamic webpage, so offline it's unusable. So that's why I found that maybe this code is enough for the Service Worker, and I don't need any cached files. (Maybe that was a mistake?)
And actually it's working fine, at least when I open my webpage, Chrome pops up the message to install the application for my webpage - and it's also working fine.
But today I have realized that in the Console there are some errors regarding it:
The FetchEvent for "https://connect.facebook.net/en_US/fbevents.js"
resulted in a network error response: the promise was rejected.
Uncaught (in promise) TypeError: Failed to fetch at
serviceWorker.js:4:21
And marks this part in the serviceWorker.js: fetch(fetchEvent.request), and says: Failed to fetch.
GET https://connect.facebook.net/en_US/fbevents.js net::ERR_FAILED
Also when I wanted to make some changes in my Facebook Pixel, it said, it can't find the Pixel for my website. However it's there. And the only modification was to add the PWA-related codes.
And I also realized that since that day the visits of my webpage shown in Google Analytics started to drop down dramatically. Not 0 now, but I think in 1-2 days it will be 0.
What is the issue here with the Service Worker?
How can I fix it?
And what is the connection between this issue and my Facebook Pixel (and Google Analytics)?
Of course I tried to search for answers, but I could not find the solution for that particular issue.
Please help me fix this issue. Hopefully the root cause is the same, so one fix would solve all.
Thank you in advance.
I found the solution - I post it here, so maybe somebody will face this issue as well, and I want to help with the solution.
So it turned out, I have to provide an offline fallback page.
I found this article, I followed the steps, created the offline.html file, modified the serviceWorker.js file, and the issue is gone, Facebook Pixel is working fine again:
https://web.dev/offline-fallback-page/

Using startTrackPage in Application Insights

I have recently been messing around with Application Insights and have been having a problem with getting the JavaScript API to work. In the default script that you are supposed to add to your page, they use the function trackPageView(). This seems to works, but I had also wanted to gather information about how long a user stayed on the page. I found the startTrackPage() and stopTrackPage() functions and tried to use those to get the information, but I always receive an error from startTrackPage().
Uncaught TypeError: appInsights.startTrackPage is not a function(anonymous function)
I have stepped through the code and the function does not seem to be created at the point I am calling it. trackPageView() is already defined though. I tried calling the function after the document loaded as well and that still failed. However, I can call it from the developer console once the page loads.
Here is where I found the information about startTrackPage() and stopTrackPage() originally. Other than that I have just been perusing around to see if anyone else has encountered this.
I appreciate the help.
Default code from App Insight:
window.appInsights = appInsights;
appInsights.startPageView();
What I have tried:
window.appInsights = appInsights;
appInsights.startTrackPage();
window.onunload = function () {
appInsights.stopTrackPage();
};
Short answer: unfortunately there's currently no way to use appInsights.startTrackPage() in the way you intend reliably.
Long answer: The reason is that startTrackPage() method is only defined in the JS that is downloaded from CDN, so until it is downloaded it is not defined.
What you could do it something like:
appInsights.queue.push(function(){appInsights.startTrackPage();})
however this would not produce correct measurement, because tracking won't start right away.
So your best approach would be record start time manually, however even that you cannot do reliably. First of all you absolutely don't want to use onunload event as at this point it will be too late for Application Insights SDK to send the data so it will most likely get lost. Using onbeforeunload and flush() will help with this problem a little bit:
var pageStart = +new Date;
window.addEventListener("beforeunload", function () {
appInsights.trackMetric("timeOnPage", (+new Date)-pageStart);
appInsights.flush();
});
However even when using onbeforeunload you are looking at high number of potential data losses - you cannot guarantee that ajax request to send data to Application Insights will complete before page navigates away and connection is interrupted. In my testing with IE was getting about 50% of losses.

JSON-P request to URL does not work?

I've been trying to get this to work for about three hours now. Searched around, looked all over actually, and I tried all the examples people showed, none of which worked. This is really starting to bug me. What I'm trying to accomplish is a call to BitCoin Charts JSON file that holds all the bitcoin data. I am setting up a webstore, and would like the price to be accurate when the user loads the page.
Here is the snippet of code where I call the $.getJSON() function:
function JSONCall() {
var url = "http://api.bitcoincharts.com/v1/weighted_prices.json";
$.getJSON(url + "?callback=?", Update);
}
function Update(data) {
//there will be code here to change the HTML on my site, but for now, this works to test
console.log(data);
}
The current error that I'm experiencing is:
Resource interpreted as Script but transferred with MIME type text/html: "http://api.bitcoincharts.com/v1/weighted_prices.json?callback=jQuery19100276493770070374_1387411109377&_=1387411109490". jquery-1.9.1.js:8336
Uncaught SyntaxError: Unexpected token :
and I cannot for the life of me get it to work. My code looks fine, according to everything I've seen this far. If anybody knows more about this than me and would be willing to help, that would be fantastic! Thanks in advance.
I checked the URL and it doesn’t return JSONP, only plain JSON.
You will need to find another way, some options come to mind:
Do a CORS request (cross-origin) if the service supports it
Run via a server-side proxy
See if the service supports JSONP in some other way

page area not refreshing using jquery and setinterval

i am trying to refresh a particular area of my php page, which will load the updated information from database. My code are working on localhost. But, when the same code i'm trying to execute on my domain. Then, it is not refreshing and not showing updated information, and i don't why... Anybody have any idea..
setInterval(updateShouts, 10000 );
function updateShouts(){
$('#refresh').load('ajax/check.php');
};
this is the code, which i'm using for refreshing the
.
I'd check that the URL is correct:
You can use Firebug (or another Javascript debugger) to watch the request going out, and you can see if it was a 404 error or if it worked.
Also, in the Console, just type in $('#refresh') and make sure it returns an actual object.
if it just displays [] or undefined, then the selector is wrong.
Try:
function updateShouts()
{
$('#refresh').load('ajax/check.php');
};
setInterval(function(){updateShouts();}, 10000 );
Problem is with most localhost dev servers the configuration, security, etc.. is usually at the load end of the scale vs a host else where. So that may or may not be part of the issue, I couldn't say for sure though
Edit I agree with the notion of checking to make sure the path ajax/check.php is valid also. And that Firebug is a very handy tool to have when developing with jquery (or javascript stand alone)

Categories

Resources