我正在尝试制作一个包含提交按钮的html,当点击按钮时我想向网络服务器发帖请求。 我要发送的内容:
curl -X GET http://192.168.2.253:8080/server/getReportData/ -d '{"project":"voda1","startDate":"1-1-2016","month":"0","endDate":"10-1-2016","simType":"0","roming":"0","latitute":"","longitude":"","radius":"","Peak":"0","kpi":[201],"name":"wavenet"}' -H "Content-Type: application/json
真正的网络服务器得到了什么:
http://192.168.2.253:8080/getReportData/%20-d%20%7B%22project%22%3A%22voda1%22%2C%22startDate%22%3A%22%22%2C%22month%22%3A%22%22%2C%22endDate%22%3A%22%22%2C%22simType%22%3A%220%22%2C%22roming%22%3A%220%22%2C%22latitute%22%3A%2220.077728%22%2C%22longitude%22%3A%2221.07728%22%2C%22radius%22%3A%2212%22%2C%22Peak%22%3A%220%22%2C%22kpi%22%3A%5B%22201%22%2C%22203%22%2C%22303%22%5D%2C%22name%22%3A%22wavenet%22%7D
如何正确地做到这一点。
以下是我的javascript for demo
JSONTest = function(){
var resultDiv = $("#resultDivContainer");
var data1 = {"user" : "mushir"};
alert(data1);
$.ajax({
url: "http://192.168.2.253:8080/server/getReportData/?",
method:'GET',
data: JSON.stringify(data1),
//data: { apiKey: "23462", method: "example", ip: "208.74.35.5" },
dataType: "json",
contentType: 'application/json',
success: function (result) {
switch (result) {
case true:
processResponse(result);
alert(result);
break;
default:
resultDiv.html(result);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
};