我在不同的div中获得json响应 json回应
{"success":"you have not inserted","error":{"name":["The name field is required."],"detail":["The detail
field is required."]}}
ajax代码
function postdata(){
var name=$('#name').val();
var detail=$('#detail').val();
var token=$('#_token').val();
$('#post').val('Submiting...');
$.ajax({
type: 'GET',
url: 'posts',
data: "name="+ name + "&detail="+ detail,
success: function(data){
} });
}
在此div
中获取json响应消息<div class="alert alert-info col-ssm-12" id="detail"></div>
<div class="alert alert-info col-ssm-12" id="name"></div>
答案 0 :(得分:0)
通过.text()或.html()
获取值function postdata(){
var name=$('#name').text();
var detail=$('#detail').text();
var token=$('#_token').val();
$('#post').val('Submiting...');
$.ajax({
type: 'GET',
url: 'posts',
data: "name="+ name + "&detail="+ detail,
success: function(data){
} });
}