1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Cors/Corb & Jquery

Discussion in 'Programming' started by sarahk, Sep 10, 2020.

  1. #1
    Google has failed me. Does anyone have a good reference on getting vanilla javascript or jquery to talk to a PHP site?

    For background:
    • All on the same domain, same server but on multiple subdomains
    • Subdomains A, B, C serve public content
    • Subdomain D holds the admin system
    • Subdomain Z holds files including javascript, css, images used by all other subdomains

    • Subdomain A wants to get some autocomplete json from Subdomain D

    Instead, I'm just going to copy over the code but it seems unnecessary. If you have any ideas I'd love to convert it back and do it properly.
     
    sarahk, Sep 10, 2020 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    What is the problem you are running in to?

    It *seems* to me based on the info provided that you are creating some sort of frontend that retrieves info from a PHP script that acts as an API serving data in JSON format and you are running in to issues with your code that is being denied by the server? If this is the case sounds like the PHP script has code restricting access to it's API from approved domains. What is the issue you are running in to?
     
    NetStar, Sep 13, 2020 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Chrome threw a corb error and returned nothing. The server returns 200, and when called directly or via postman the output is correct. All the cors stuff is in there. I've written all the code but because the code calls another API I was wanting to have a single point of contact.
     
    sarahk, Sep 13, 2020 IP
  4. Efetobor Agbontaen

    Efetobor Agbontaen Active Member

    Messages:
    136
    Likes Received:
    41
    Best Answers:
    5
    Trophy Points:
    85
    #4
    Okay it's the normal CORS issue.
    If you use Apache Webserver, you can add this:
    Header Set Access-Control-Allow-Origin "*"
    to your Sub Domain D vhost file.

    You can also add it to your .htaccess file in the root of Subdomain D.

    Alternatively, you can do it from PHP by adding this:
    header("Access-Control-Allow-Origin: *");

    Lastly, if Subdomain A is accessed only by you and you use Google Chrome, you can simply just download any "Allow-Control-Allow-Origin" Extension from Chrome store. They will disable the security feature on Chrome.
    But this will only make it work on your computer.
     
    Efetobor Agbontaen, Sep 18, 2020 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Nah, sorted out the cors issues. This was another layer, and I can't control the browser that people use.
     
    sarahk, Sep 18, 2020 IP