Simple jQuery, PHP and JSONP example?

后端 未结 7 2182
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 16:36

I am facing the same-origin policy problem, and by researching the subject, I found that the best way for my particular project would be to use JSONP to do cross-origin requ

7条回答
  •  名媛妹妹
    2020-11-22 16:55

    Simple jQuery, PHP and JSONP example is below:

    window.onload = function(){
    	$.ajax({
    		cache: false,
    		url: "https://jsonplaceholder.typicode.com/users/2",
    		dataType: 'jsonp',
    		type: 'GET',
    		success: function(data){
    			console.log('data', data)
    		},
    		error: function(data){
    			console.log(data);
    		}
    	});
    };

提交回复
热议问题