在此代码中,我在 success
函数中遇到问题。我尝试了很多,但它会转到 error
函数。 #action-button
调用 JavaScript 方法。
<button id="action-button">Click me to load info!</button>
<div id="info"></div>
<small>
Demo created by <a href="https://twitter.com">Twitter</a>
</small>
$('#action-button').click(function() {
$.ajax({
url: 'sampleurl',
data: { format: 'json' },
error: function() {
$('#info').html('<p>An error has occurred</p>');
},
dataType: 'jsonp',
success: function(data) {
$('#info').html('<p>Successd</p>');
},
type: 'GET'
});
});
最佳答案
如果您要将 json 发送到服务器,请尝试添加 conententType: application/json
您还期望响应是 jsonp 内容类型吗?这方面的不匹配也可能是问题所在。
关于javascript - ajax GET 方法中未调用成功函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29073665/