Fengist's Recent Forum Activity

  • Found it.

    This kinda explains it. It's called 'mixed content'

    developers.google.com/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content

    It's not that it isn't supported, it's a security hole for HTTPS. When you go from a HTTPS site and make a request to a HTTP site, it falls under the 'mixed content' and gets blocked.

    If you made the AJAX call from an HTTP site to another HTTP site, it would likely have gone through without issue. It was the call from HTTPS to HTTP that caused the problem.

    preview.construct.net is an HTTPS site.

  • I do not have HTTPS certificate on the server. Maybe this is a problem?

    That is almost definitely the problem.

    I'm going to venture a guess that the J5 is using an older version of Chrome that allowed you to access non secure sites but it doesn't give the http origin as a security measure, which would normally get blocked by AJAX being off-site. That's most likely is why you're seeing it's IP and not an origin. You may have been allowed to run your previous script as it allowed any site to run it. My script only allows specific sites to access it so it would have failed to run.

    The J6 and the desktop are using newer versions of Chrome which are simply refusing to let you go from a secure site (https://preview.construct.net) to your insecure site (http://www.mysite.com) which is why they're not even attempting to make the AJAX call.

    It's the same problem the other guy was having in the post I linked to: trying to make an AJAX call to a http site.

  • And this brings up another question. If you're accessing it from the phone's browser, which browser are you using? The Samsung browser or Chrome?

  • Ok, that's a start.

    If you see an IP in the httporigin.log then that means that it's being called from somewhere outside of your domain and I'd be surprised if it gave a response. What you should see is something like this:

    preview.construct.net

    mydomain.com

    My next question. Do you have an HTTPS certificate on the site you're trying to access?

  • If it works, then it's all good.

    Years ago when programmers had to write code for Commodore 64's they had to be super efficient. They had to write elegant code in order to make it fit in 64k of ram and they had to make it elegant in order to run quickly on an 8 bit CPU.

    Today, programmers have a LOT more freedom to write functional code rather than elegant.

    The questions you need to ask yourself as to whether your method is the best.

    1. Does the code work as intended?

    2. Can you follow how the code works?

    3. Is this code for public consumption or just for internal use?

    Does the code do what you want, does it do it quickly enough, does it not gobble an excess of ram... is it functional?

    The only time I get concerned with elegance is if I'm writing code for someone other than myself who also understands how to write code. In that case, I try to make it elegant so they don't think I'm a total noob. For my own use, I comment my code so I can come back later and figure out "what the hell was I thinking."

    In all honesty, the vast majority of your end users won't give a damn about code elegance. What they will give a damn about is how it looks, is it fast and does it contain bugs.

  • You do not have permission to view this post

  • Your English is just fine.

    Yea, it's pretty annoying not to see what the actual AJAX error is.

    If you read further down that post above there's some code to log incoming requests to file so you can actually see if the AJAX requests are coming through. That would be my first test to see if the various devices are even making the requests and if they are, do they have an origin.

  • Thanks Ashley ! I think the JS noob gets it! This is really cool, being able to call a custom JS function inside a layout.

    This works by calling skillStart() on start of layout and skillStop() on end of layout (to prevent it from creating multiple intervals) and basically, (along with some CSS) pulses a progress bar between two values.

    function anipgbar() {
     var p = document.getElementsByClassName("animated");
     var orig = parseInt(p[0].getAttribute('data-orig'));
     var cval = parseInt(p[0].getAttribute('value'));
     if (cval > orig) {
     p[0].setAttribute('value', orig);
     } else
     {
     p[0].setAttribute('value', orig + 1);
     }
    };
    
    var drawInterval;
    
    function skillStop() {
     clearInterval(drawInterval); 
    };
    
    function skillStart() {
     drawInterval = setInterval(anipgbar, 2000);
    };
    
  • And here's a little trick you can use to see if the AJAX call is actually going through

    replace

    if (isset($_SERVER['HTTP_ORIGIN'])){
     $http_origin = $_SERVER['HTTP_ORIGIN'];
    }
    else
    {
     die();
    }
    

    with this:

    $myfile = fopen("httporigin.log", "a") or die();
    
    if (isset($_SERVER['HTTP_ORIGIN'])){
     $http_origin = $_SERVER['HTTP_ORIGIN'];
     fwrite($myfile, $http_origin."\n");
     fclose($myfile);
    }
    else
    {
     fwrite($myfile, $_SERVER['REMOTE_ADDR']."\n");
     fclose($myfile);
     die();
    }
    
    

    What this will do is create a .txt file in the directory where this script is called httporigin.log.

    If an incoming request has an origin, it will add that url to the text file. If it doesn't have an origin, it will instead log the ip address.

    This is real handy for determining where your AJAX requests are coming from.

  • Right, I believe it's like I said. I seem to recall reading recently that the C3 AJAX specifically looks for the HTTPS, something I don't think C2 did.

    I know if I change the URL's in that script above to http that it won't work.

  • Just posted this reply elsewhere. See if this fixes it:

    construct.net/en/forum/construct-3/general-discussion-7/ajax-changed-recently-not-140404

  • Oh, and once you have it all running and working, delete the two lines of error reporting...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Fengist's avatar

Fengist

Member since 6 Nov, 2015

Twitter
Fengist has 5 followers

Trophy Case

  • 9-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • x3
    Coach One of your tutorials has over 1,000 readers
  • x2
    Educator One of your tutorials has over 10,000 readers
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

16/44
How to earn trophies