jquery使用ajax發送數據到服務器
function post(data, path) {
$.ajax({
type: "POST",
url: path,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data: data,
dataType: "json",
success: function (message) {
console.log(message);
},
error: function (message) {
console.log(message);
}
});
}
使用到時候直接調用這個方法就可以了
$(function(){
var tel = $("#tel").val();
var data = {"tel": tel};
post(data, "http://www.baidu.com");
});