通过POST(PHP)发送JSON有效负载

时间:2015-12-11 05:56:16

标签: php json http-post payload

我有这些数据。我怎样才能将其发送到特定的URL并阅读回复。

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

2 个答案:

答案 0 :(得分:1)

您可以使用$.post简写$.ajax使用jQuery,

喜欢这个 -

$.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 */ }
);

答案 1 :(得分: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'
    });
相关问题