K
K
KnightForce2017-05-05 18:28:10
CORS
KnightForce, 2017-05-05 18:28:10

Cross domain request from http to https via ajax or fetch?

dataType: jsonp is not supported.
There are two options, both don't work:
1) Ajax.

$.ajax(api, {
    crossDomain: true
    success: (data)=>{
        console.log(data);
    },
});


2) fetch:
fetch(api, {
      mode: "cors",
    });
    queryPromise.then((response)=>{
      console.log(data);
    })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-05-05
@devspec

Firstly, cross-domain requests only work when the server returns Allow-Control-Allow-Origin: *
Secondly, you can try to put processData: falsein the parameters of your ajax request.

$.ajax({
    type: "POST",
    url: api_url,
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    processData: false,
    data: JSON.stringify(pd),
    success: function (result) {
        // ...
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question