1

I am trying to make an AJAX request via jQuery to a PHP script present in a different server (say the IP is 11.1.35.12) and the location of PHP script is "C:\inetpub\wwwroot\Kibana\mytelemetry.php" inside the server. What should be the url in my below ajax code?

$.ajax({

    url     :   "11.1.35.12/Kibana/mytelemetry.php",
    cache   :   false,
    data    :   ({
                    DshBrdName  : strFullDashBoardName,
                    DshBrdID    : currentDashboard, 
                    r           : Math.random()
                }),
    success :   function(data, textStatus, jQxhr){
                    //alert(textStatus); 
                },
    error   :   function(jqXHR, textStatus, errorThrown){
                    //alert(textStatus);
                    alert(errorThrown);
                },
    type    :   "POST"
});

P.S : The above is not working! I am pretty sure my url format is wrong.

1

1 Answer 1

2

You're missing the http protocol when passing in url and your script is requesting url in the current domain you're in.

try this:

$.ajax({

    url     :   "http://11.1.35.12/Kibana/mytelemetry.php",
    cache   :   false,
    data    :   ({
                    DshBrdName  : strFullDashBoardName,
                    DshBrdID    : currentDashboard, 
                    r           : Math.random()
                }),
    success :   function(data, textStatus, jQxhr){
                    //alert(textStatus); 
                },
    error   :   function(jqXHR, textStatus, errorThrown){
                    //alert(textStatus);
                    alert(errorThrown);
                },
    type    :   "POST"
});

Beside that, you have to add Access-Control-Allow-Origin header in your php script

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please let me know the headers I need to add in my PHP script?
The simplest way to do this is just adding line header('Access-Control-Allow-Origin: *'); somewhere in your script. Preferably at the very beginning, because you cannot set headers after sending response (like echo or var_dump()). Also, you can (and probably should) replace * sign with your domain (without protocol). There's a good reading about it on MDN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.