我正在尝试通过 jQuery 向不同服务器中存在的 PHP 脚本发出 AJAX 请求(假设 IP 是 11.1.35.12),PHP 脚本的位置是“C:\inetpub\wwwroot\Kibana\mytelemetry. php”在服务器中。我下面的 ajax 代码中的 url 应该是什么?
$.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 : 以上是行不通的!我很确定我的 url 格式是错误的。
最佳答案
您在传递 url 时缺少 http
协议(protocol),并且您的脚本正在请求您所在的当前域中的 url。
试试这个:
$.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"
});
除此之外,您还必须在您的 php 脚本中添加 Access-Control-Allow-Origin
header
关于javascript - 使用 jQuery 的 AJAX 调用中的 url 字段格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39105368/