When to use json and jsonp with jquery $ .ajax?

On our site, some pages are SSL and some are not SSL.

Example:

http://www.example.com/search/patients
https://www.example.com/patients

Now I am looking for patients on the page http://www.example.com/search/patientsand will send a server request https://www.example.com/patientsthrough the jQuery $.ajaxand function dataType=json. I can not get the data.

Questions:

  • Should I use jsonpwhen we request from httpto httpsor httpsto httpon the same server?

  • If I use SSL for both URLs then it will only work with dataType=json

thank

+3
source share
3 answers

- ajax , : , ( ) HTML, script,

, script .

:

+5

SSL URL-, . , @Waqas Raja, URL.

. $.ajax({url: '/search/patients'})

+3

You need to use either CORS, or a proxy, or JSONP to receive content from another source. Changing the scheme (from http to https or vice versa) changes its origin.

Retrieving data from a secure server to an insecure page eliminates many of the benefits of using SSL.

If you retrieve both pages and the data source via SSL, you can use plain JSON and not introduce these security issues.

+1
source

All Articles