Answer the question
In order to leave comments, you need to log in
How to get JSON via Ajax post request from php from someone else's domain?
Here is the ipi demo of Yandex maps
. From this address http://www.freeway.by/ajax/element_list.php you need to get Json on js with a list of objects for the city of Gomel and so that the objects are displayed on the map in the example above
Help write js code for implementations!
Answer the question
In order to leave comments, you need to log in
var settings = {
"async": true,
"crossDomain": true,
"url": "http://www.freeway.by/ajax/element_list.php",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
},
"data": {
"data1": "{\"=PROPERTY_49\":[\"\\u0413\\u043e\\u043c\\u0435\\u043b\\u044c\"],\"=PROPERTY_50\":[\"51\",\"42\",\"47\",\"46\",\"49\",\"48\",\"43\",\"44\",\"40\",\"41\",\"45\",\"50\"],\"=PROPERTY_6\":[\"29\",\"31\",\"30\"],\"toilet_avail\":\"2\"}"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
If you try to access from one domain via ajax to another, then such a request will be faked, because it is cross-domain and in most cases such requests are prohibited for security reasons. For cross-domain requests, you can use JSONP or CORS technologies. But the server, for its part, must support them.
www.freeway.by/ajax/element_list.php:
function run(){
$data = ['x'=>'y'];
header('Content-Type: application/json');
echo json_encode($data);
}
$.ajax({
url: "http://www.freeway.by/ajax/element_list.php"
}).done(function(data) {
objectManager.add(data);
});
If the second domain is under your control, then there is a setting in the request header that can be configured to allow requests from some specific domains or all. If nnt control to another domain, then you can only do this for a specific browser that is launched specifically from your computer locally in a special way, so that it is a public site and goes by Ajax to other people's domains as they wrote above - it won't work, only the bypass paths are not universal
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question