【发布时间】:2018-01-04 09:15:25
【问题描述】:
我已经找了几个小时,但仍然不知道如何解决它,
我有一个这样的json数据
{
"salutation" : "tes",
"location" : "tes",
"reference_code" : "tes",
"isCustomer" : 1,
"email_to" : "yudi@nawadata.com",
"phone" : "089999999",
"front_name" : "Adhitya",
"name" : "Adhitya",
"age" : 13,
"marital_status" : "tes",
"dependents" : "tes",
"income" : "100000",
"cover" : ["Legacy","Education","Retirement"],
"total_allocated" : 10000000,
"total_tuition" : 300000,
"total_cost" : 200000,
"total_gap" : 1211212121,
"target" : "2323232323",
"file_name" : "tes",
"language" : "id",
"isFromUmbrella" : 1,
"collegeperiod" : 2017,
"collegeage" : 14,
"collegecosttotal" : 2000000,
"sangatpenting" : "tes",
"tigaprioritas" : "tes",
"arr_child" : [{
"name" : "coba",
"monthly_saving" : 20000,
"educost" : 2000,
"destination_university" : 10000,
"year_to_university" : 1000,
"year" : 2017
}],
"arr_triangle" : [
{
"name" : "invesment",
"background" : "#c00",
"size" : 1
},
{
"name" : "retirement",
"background" : "#c00",
"size" : 1
},
{
"name" : "education",
"background" : "#c00",
"size" : 1
},
{
"name" : "legacy",
"background" : "#c00",
"size" : 1
},
{
"name" : "health",
"background" : "#c00",
"size" : 1
},
{
"name" : "life",
"background" : "#c00",
"size" : 1
}
]
}
但是每次我点击按钮时,它只是加载而没有任何反馈给我,我做错了什么吗?
这是 JS 代码:
function sendoi()
{
var ItemJSON = {"salutation":"tes","location":"tes","reference_code":"tes","isCustomer":1,"email_to":"yudi@nawadata.com","phone":"089999999","front_name":"Adhitya","name":"Adhitya","age":13,"marital_status":"tes","dependents":"tes","income":"100000","cover":["Legacy","Education","Retirement"],"total_allocated":10000000,"total_tuition":300000,"total_cost":200000,"total_gap":1211212121,"target":"2323232323","file_name":"tes","language":"id","isFromUmbrella":1,"collegeperiod":2017,"collegeage":14,"collegecosttotal":2000000,"sangatpenting":"tes","tigaprioritas":"tes","arr_child":[{"name":"coba","monthly_saving":20000,"educost":2000,"destination_university":10000,"year_to_university":1000,"year":2017}],"arr_triangle":[{"name":"invesment","background":"#c00","size":1},{"name":"retirement","background":"#c00","size":1},{"name":"education","background":"#c00","size":1},{"name":"legacy","background":"#c00","size":1},{"name":"health","background":"#c00","size":1},{"name":"life","background":"#c00","size":1}]}
$.ajax({
url: 'http://localhost/dbsapi/api/data/postpdfeducation',
type: 'POST',
contentType: 'application/json',
data: ItemJSON,
dataType: "json",
success: function(){
alert('hello');
},
error: function(){
alert('error');
}
});
};
HTML:
<button type="submit" onclick="sendoi()" class="site-font-light mobile-handler">Submit</button>
【问题讨论】:
-
你用的是什么版本的jQuery?
-
这是因为您正在单击提交按钮,所以推测父元素
<form>正在提交。您应该改为挂钩到该表单的submit事件,并在该事件上调用preventDefault()。 -
@31piy 我正在使用 jquery-1.12.4.js
-
@RoryMcCrossan 先生,你有一个例子吗,我是 html 新手,所以我不知道这是什么意思
-
好的,我给你加了答案