[英]JQuery JSON not returning data
我正試圖從我的其他主機獲取游戲服務器數據,因為我的主要主機不允許服務器查詢。 但我現在遇到了json的問題..
我的代碼:
<script type='text/javascript'>
$(document).ready(function(){
$("input.senddata").click(function() {
var ipForm = $('input[name="ip_submit"]').val();
var gameForm = $( 'select[name="game_submit"]' ).val()
$.getJSON("http://gamepwn.net/serversdotee/add-server.php?json=true",
{
ip: ipForm,
game: gameForm
},
function(data) {
$('.result').html(data);
});
});
});
</script>
我想要獲取的數據是一個簡單的文本,例如“已查詢服務器”。
您的“其他服務器”需要返回正確的CORS標頭,或者您需要移動到JSONP
數據類型並修改“其他服務器”,以便它正確返回JSONP
而不是JSON
。
JSONP與JSON:
JSON: http://gamepwn.net/serversdotee/add-server.php?json=true
: http://gamepwn.net/serversdotee/add-server.php?json=true
json = http://gamepwn.net/serversdotee/add-server.php?json=true
{"foo":"bar"}
JSONP: http://gamepwn.net/serversdotee/add-server.php?json=true&callback=??
: http://gamepwn.net/serversdotee/add-server.php?json=true&callback=??
json = true&callback = http://gamepwn.net/serversdotee/add-server.php?json=true&callback=??
jQuery_7891469862340189270349182561({"foo":"bar"})
其中jQuery_7891469862340189270349182561
是回調GET參數的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.