4,250
社区成员
发帖
与我相关
我的任务
分享
function searchAction()
{
//获取数据库内容
$registry = Zend_Registry::getInstance();
$loKkcheckIn = new Mykkdj();
$dbAdapter = $loKkcheckIn->getAdapter();
$filter = new Zend_Filter_StripTags();
$result = array();
//接收POST传递过来的参数
// if ($_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest")
// {
$lcsFormFiledName= $filter->filter($this->_request->getPost('name'));
$lcsFormValue = $filter->filter($this->_request->getPost('val'));
// if(!empty($lcsFormValue))
// {
// $sWhereSQL=$dbAdapter->quoteInto($lcsFormFiledName.' LIKE %?%',$lcsFormValue);
// }
// $result=$loSysCode->fetchAll($sWhereSQL)->toArray();
//
$result = array(
"Great Bittern"=>"Botaurus stellaris",
"Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Little Bittern"=>"Ixobrychus minutus",
"Black-crowned Night Heron"=>"Nycticorax nycticorax",
"Purple Heron"=>"Ardea purpurea",
"sPOst"=>"\"".$lcsFormFiledName." ".$lcsFormValue."\""
);
// }
foreach ($items as $key=>$value) {
array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key)));
}
echo array_to_json($result);(该函数已经存在并正常工作)
}
POST:
Array
(
[name] => sDriverBarCode
[val] => 34534
)
Global:
Array
(
[GLOBALS] => Array
*RECURSION*
[_POST] => Array
(
[name] => sDriverBarCode
[val] => 34534
)
[_GET] => Array
(
)
[_COOKIE] => Array
(
[PHPSESSID] => 5ihs2i8o5cbqgen43he5a0ann5
)
[_FILES] => Array
(
)
[_ENV] => Array
(
)
[_REQUEST] => Array
(
[name] => sDriverBarCode
[val] => 34534
)
[_SERVER] => Array
(
[HTTP_X_REQUESTED_WITH] => XMLHttpRequest
[HTTP_ACCEPT_LANGUAGE] => zh-cn
[HTTP_REFERER] => http://localhost/zframework/index/home
[HTTP_ACCEPT] => application/json, text/javascript, */*
[CONTENT_TYPE] => application/x-www-form-urlencoded
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
[HTTP_HOST] => localhost
[CONTENT_LENGTH] => 29
[HTTP_CONNECTION] => Keep-Alive
[HTTP_CACHE_CONTROL] => no-cache
[HTTP_COOKIE] => PHPSESSID=5ihs2i8o5cbqgen43he5a0ann5
[PATH] => C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;d:\php5;c:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;E:\Downloads\ZendFramework-1.10.7\bin;C:\Program Files\MKVtoolnix;
[SystemRoot] => C:\Windows
[COMSPEC] => C:\Windows\system32\cmd.exe
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
[WINDIR] => C:\Windows
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache/2.2.15 (Win32) PHP/5.3.3
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => D:/Apache/htdocs
[SERVER_ADMIN] => jianglg2008@126.com
[SCRIPT_FILENAME] => D:/Apache/htdocs/search.php
[REMOTE_PORT] => 52292
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /search.php
[SCRIPT_NAME] => /search.php
[PHP_SELF] => /search.php
[REQUEST_TIME] => 1292467994
)
[sFile] => ./log111.txt
[handle] => Resource id #3
)
(已经放在$(document).ready()中)
$("input#sDriverBarCode").autocomplete({
source: function( request, response ) {
$.ajax({
url: "<?php echo $this->baseUrl;?>/index/search",
type: "post",
dataType: "json",
data: {
name: "sDriverBarCode",
val: $("input#sDriverBarCode").val()
},
success: function( data ) {
response( $.map( data, function( item ) {
alert("val="+item.value);
return {
label: item.kID ,value: item.sDriverBarCode
}
}));
}
});
},
minLength: 1,
select: function( event, ui ) {
"Selected: " + ui.item.label +",Nothing selected, input was " + this.value;
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
Array
(
[name] => sDriverBarCode
[val] => a
)
Global:
Array
(
[GLOBALS] => Array
*RECURSION*
[_POST] => Array
(
[name] => sDriverBarCode
[val] => a
)
[_GET] => Array
(
)
[_COOKIE] => Array
(
[PHPSESSID] => nh18v41vjihoqbt7lvgb1hjqh7
)
[_FILES] => Array
(
)
[_ENV] => Array
(
)
[_REQUEST] => Array
(
[name] => sDriverBarCode
[val] => a
)
[_SERVER] => Array
(
[HTTP_X_REQUESTED_WITH] => XMLHttpRequest
[HTTP_ACCEPT_LANGUAGE] => zh-cn
[HTTP_REFERER] => http://localhost/zframework/index/home
[HTTP_ACCEPT] => application/json, text/javascript, */*
[CONTENT_TYPE] => application/x-www-form-urlencoded
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
[HTTP_HOST] => localhost
[CONTENT_LENGTH] => 25
[HTTP_CONNECTION] => Keep-Alive
<?php
ob_start();
$sFile="./log111.txt";
$handle = fopen($sFile,"a+");
Print_r($_GET);
print_r($_POST);
echo "Global:\r\n";
print_r($GLOBALS);
@fwrite($handle,ob_get_contents());
@fclose($handle);
@ob_end_clean();
function array_to_json( $array ){
if( !is_array( $array ) ){
return false;
}
$associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
if( $associative ){
$construct = array();
foreach( $array as $key => $value ){
// We first copy each key/value pair into a staging array,
// formatting each key and value properly as we go.
// Format the key:
if( is_numeric($key) ){
$key = "key_$key";
}
$key = "\"".addslashes($key)."\"";
// Format the value:
if( is_array( $value )){
$value = array_to_json( $value );
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "\"".addslashes($value)."\"";
}
// Add to staging array:
$construct[] = "$key: $value";
}
// Then we collapse the staging array into the JSON form:
$result = "{ " . implode( ", ", $construct ) . " }";
} else { // If the array is a vector (not associative):
$construct = array();
foreach( $array as $value ){
// Format the value:
if( is_array( $value )){
$value = array_to_json( $value );
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "'".addslashes($value)."'";
}
// Add to staging array:
$construct[] = $value;
}
// Then we collapse the staging array into the JSON form:
$result = "[ " . implode( ", ", $construct ) . " ]";
}
return $result;
}
$result = array();
$items = array(
"Great Bittern"=>"Botaurus stellaris",
"Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Little Bittern"=>"Ixobrychus minutus",
"Black-crowned Night Heron"=>"Nycticorax nycticorax",
"Purple Heron"=>"Ardea purpurea"
);
foreach ($items as $key=>$value) {
array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key)));
}
echo array_to_json($result);
?>

//是否能这样
success: function( data ) {
return "{label: a ,value: b }";
}
function array_to_json( $array ){
if( !is_array( $array ) ){
return false;
}
$associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
if( $associative ){
$construct = array();
foreach( $array as $key => $value ){
// We first copy each key/value pair into a staging array,
// formatting each key and value properly as we go.
// Format the key:
if( is_numeric($key) ){
$key = "key_$key";
}
$key = "\"".addslashes($key)."\"";
// Format the value:
if( is_array( $value )){
$value = array_to_json( $value );
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "\"".addslashes($value)."\"";
}
// Add to staging array:
$construct[] = "$key: $value";
}
// Then we collapse the staging array into the JSON form:
$result = "{ " . implode( ", ", $construct ) . " }";
}
else { // If the array is a vector (not associative):
$construct = array();
foreach( $array as $value ){
// Format the value:
if( is_array( $value )){
$value = array_to_json( $value );
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "'".addslashes($value)."'";
}
// Add to staging array:
$construct[] = $value;
}
// Then we collapse the staging array into the JSON form:
$result = "[ " . implode( ", ", $construct ) . " ]";
}
return $result;
}
//编码
$this->myjson =json_encode($this->array);
//返回json
echo $this->myjson;
//接收json
function(data){
var myjson="";
eval('myjson=' + data + ';');
//2维数组
$(".Name_view").html(myjson[0]['name']);
}
{ "Great Bittern": "Botaurus stellaris", "Little Grebe": "Tachybaptus ruficollis", "Black-necked Grebe": "Podiceps nigricollis", "Little Bittern": "Ixobrychus minutus", "Black-crowned Night Heron": "Nycticorax nycticorax", "Purple Heron": "Ardea purpurea", "sPOst": "\" \"", "key_0": { "id": "Botaurus stellaris", "label": "Great Bittern", "value": "Great Bittern" }, "key_1": { "id": "Tachybaptus ruficollis", "label": "Little Grebe", "value": "Little Grebe" }, "key_2": { "id": "Podiceps nigricollis", "label": "Black-necked Grebe", "value": "Black-necked Grebe" }, "key_3": { "id": "Ixobrychus minutus", "label": "Little Bittern", "value": "Little Bittern" }, "key_4": { "id": "Nycticorax nycticorax", "label": "Black-crowned Night Heron", "value": "Black-crowned Night Heron" }, "key_5": { "id": "Ardea purpurea", "label": "Purple Heron", "value": "Purple Heron" }, "key_6": { "id": "\" \"", "label": "sPOst", "value": "sPOst" } }