// 禁用按钮防止重复提交
$(function(){
$('form input[type=button]').click(function(){
var cityval=$('form input[name=city]').val();
$.ajax({
type:'POST',
url:'http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&bk_key='+cityval+'&bk_length=600',
dataType:'jsonp',
success: function(response,status,xhr){
console.log(response);
document.write(response.copyrights);
},error: function(){
alert('aaa');
},complete: function(){
$('form input[type=button]').removeAttr("disabled"); 提交完成后,提交按钮能按
},beforeSend: function(){
$('form input[type=button]').attr({ disabled: "disabled" }); 提交后 禁用提交按钮
},
})
})
})
<form method="post" name="form">
<input type="text" name="city" value="威海">
<input name="" type="button" value="提交">
</form>
<div class="box1"></div>
</body>
</html>
<script>
$(function(){
$('form input[type=button]').click(function(){
var cityval=$('form input[name=city]').val();
var div=' ';
$.ajax({
type:'POST',
url:'http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&bk_key='+cityval+'&bk_length=600',
dataType:'jsonp',
success: function(response,status,xhr){
console.log(response);
console.log(response.card[0].value);
for(var i=0;i<response.card.length;i++){
div+='<p>'+response.card[i].name+':'+response.card[i].value+'</p>' ; //追加ajax的值到div当中,这样查询按钮就会一直在页面,如果不追加到div当中,直接document.write,输出就会把查询输入 覆盖
}
$(".box1").html(div);
}
})
})
})
</script>