我正在尝试重新创建https://jqueryui.com/autocomplete/#remote-jsonp 用我自己的数据库
test.php的内容
<?php
$host = "localhost";
$user = "root";
$pass = "*";
$databaseName = "easychartdb";
$connect = mysqli_connect($host,$user,$pass,$databaseName);
$sql = "Select * from `calendar`";
$result = mysqli_query($connect,$sql);
$json_array = array();
$array = mysqli_fetch_row($result);
while($row = mysqli_fetch_row($result))
{
$json_array[] = $row;
}
echo json_encode($json_array);
?>
tester.html的内容。从链接中更改的是源:test.php和错误函数
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Remote JSONP datasource</title>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
.ui-autocomplete-loading {
background: white url("images/ui-anim_basic_16x16.gif") right
center no-repeat;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<script>
$( function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#birds" ).autocomplete({
source: function( request, response ) {
$.ajax( {
url: "test.php",
dataType: "jsonp",
data: {
term: request.term
},
success: function( data ) {
response( data );
}
,
error: function (err) {
console.error("error");
console.log(err);
console.log(err.stack);
}
} );
},
minLength: 2,
select: function( event, ui ) {
log( "Selected: " + ui.item.value + " aka " + ui.item.id );
}
} );
} );
</script>
</head>
<body>
<div class="ui-widget">
<label for="birds">Birds: </label>
<input id="birds">
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;"
class="ui-widget-content"></div>
</div>
</body>
</html>
控制台日志始终会引发错误
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ ( statusText )
always: ƒ ()
complete: ƒ ()
done: ƒ ()
error: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ ( key )
overrideMimeType: ƒ ( type )
pipe: ƒ ( /* fnDone, fnFail, fnProgress */ )
progress: ƒ ()
promise: ƒ ( obj )
arguments: null
caller: null
length: 1
name: "promise"
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: jquery-1.12.4.js:3431
[[Scopes]]: Scopes[3]
readyState: 4
responseText: "[["2","central medical","ryan","ryan","ryan","2019-02-
06 00:00:00","2019-02-07 00:00:00"]]"
setRequestHeader: ƒ ( name, value )
state: ƒ ()
status: 200
statusCode: ƒ ( map )
arguments: null
caller: null
length: 1
name: "statusCode"
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: jquery-1.12.4.js:9552
[[Scopes]]: Scopes[3]
0: Closure (ajax) {type: "closure", name: "ajax", object: {…}}
1: Closure {type: "closure", name: "", object: {…}}
2: Global {type: "global", name: "", object: Window}
statusText: "OK"
success: ƒ ()
then: ƒ ( /* fnDone, fnFail, fnProgress */ )
__proto__: Object
任何人都可以帮助我解决这里的问题,谢谢!
答案 0 :(得分:0)
您正在使用self.tFPeriodEndCurrent.inputView = self.datePicker
,但没有返回回调。因此,有两种选择。将dataType更改为json或修正您的返回值:
tester.html:
//assume textfield contains 20/2/2019 , that should reflect in UIdatepicker when user Tap on textfield.
how to acheive that! any help
test.php:
jsonp
代替
dataType: 'jsonp',
jsonpCallback: 'callback',
Here,您可以找到有关jsonp的一些信息。