jQuery Ajax on Different Port

后端 未结 6 630
灰色年华
灰色年华 2020-12-11 06:38

My php file located at port 80 (default port) while my ajax call are on port 8080.

My index.html on port 8080

$(document).ready(function(){
$.get(\"u         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 06:51

    The Same Origin Policy (SOP) denies Javascript from sending requests to any other host and port than the one it was downloaded from.

    What is needed to work around this is a programm running on the same host and port as the origin of the javascript that forwards requests to the the actual service. A program that acts like this is commonly called a proxy, so what is needed is a JSONP proxy.

    If your server was running ruby/rails and sinatra, github.com/greenisus/jsonp-proxy would be a minimal solution. A solution for PHP that seems to have many features would be benalman.com/projects/php-simple-proxy/.

提交回复
热议问题