2015-12-11 34 views
-1

我有這些數據。我怎麼能發送到一個特定的URL並閱讀迴應。通過POST(PHP)發送JSON有效負載

{ 
    "agent": { 
    "name": "Minecraft", 
    "version": 1 
    }, 
    "username": "mojang account name/email", 
    "password": "mojang account password", 
} 
+0

你把從服務器端或客戶端的這些數據? – Ikari

+0

它正在發送客戶端 –

回答

0

您可以使用AJAX向它發送如下

  • url - 向何處發送數據
  • data - 要發送
  • error什麼 - 在Ajax調用的情況下,結果出錯
  • dataType - 你會收到什麼樣的數據
  • success - 什麼從服務器
  • type接收響應之後 - 的請求

類型。

$.ajax({ 
     url: 'http://example.com/sample/get_respose.php', 
     data: { 
      "agent": { 
       "name": "Minecraft", 
       "version": 1 
      }, 
      "username": "mojang account name/email", 
      "password": "mojang account password" 
      }, 
     error: function() { 
      $('#info').html('<p>An error has occurred</p>'); 
     }, 
     dataType: 'jsonp', 
     success: function(data) { 
      // use your response data 
     }, 
     type: 'GET' 
    }); 
1

可以使用$.post簡寫使用jQuery $.ajax

這樣的 -

$.post(
"script.php", { 
"agent": { 
"name": "Minecraft", 
"version": 1 
}, 
"username": "mojang account name/email", 
"password": "mojang account password", 
}, 
function(dataReturned){ /* do something with data returned from the script */ } 
);