<script>
var addUser = function() {
var defer = $.Deferred()
$.ajax("http://localhost/PhpProject1/index.php", {
type: "POST",
jsonpCallback: 'yes',
data: {username: 'test'},
contentType: "application/json",
dataType: "jsonp"
});
success:(function(data) {
defer.resolve(data);
})
}
filtered = defer.then(function(value) {
return value;
});
filtered.done(function(value) {
console.log(value);
});
$("button").on("click", addUser);
</script>
我创建了上面的函数来从 jsnop 检索数据。这里我使用了 Defered 。但是当我尝试这段代码时,我得到了以下错误。
Uncaught ReferenceError: defer is not defined