我使用jQuery回调函数从insert.php接收一个JSON对象到insert.js文件。
正在正确接收对象,但是当我尝试将其输出到屏幕时
我收到错误:
"TypeError:a is undefined"
jQuery.js
JSON
{"result":{"name":"asdasd ","location":"asdasdas","email":"asd"}}
HTML
<form id="InsertEventForm" action="insert.php" method="post">
<p>Event Name:<br />
<input id="name" type="text" name="name" />
</p>
<p>Event Location :<br />
<input id="location" type="text" name="location" />
</p>
<p>Email:<br />
<input type = "email" name="email" />
</p>
<p>
<button id="insertSubmit">Save</button></a>
</p>
</form>
的JavaScript
$("#insertSubmit").click( function() {
$.post( $("#InsertEventForm").attr("action"), $("#InsertEventForm :input").serializeArray(), function(info){
var output='<ul>';
$.each(info.result,function(key,val){
output+='<li>';
output+='<h3>Event Name:' + val.name + '</h3>';
output+='<p>Location:' + val.location + '</p>';
output+='<p>Contact:'+ val.email + '</p>';
output+='</li>';
console.log(output)
});
output+='</ul>';
$('#result').html(output); // Out put the update div
});
clearInput();//******clears the fields *//
});
$("#InsertEventForm").submit( function() {
return false;
});
我该如何解决这个问题?