我正在尝试创建一个动态搜索功能,但是我无法解决这个问题。
以下代码有什么问题?
JSON:
...
$result=$obj->Decode_Serialize($resource);// method to unserialize string value
$text= isset($result['text_department_code']) ?
$result['text_department_code']: 'a';
if(!empty($search) && !empty( $checkbox) && !empty($match) && !empty($sort) && !empty($text))
{
echo $text= $result['text_department_code']; // error Notice: Undefined index: text_department_code in line 18
print $text;
print_r($result);
}
...
我不知道为什么它只是根本不工作甚至isset已被包括在内。 // $结果[ 'text_department_code'];
print_r($result) output:
Array
(
[search_deparment_code] => department_code
[checkbox_deparment_code] => true
[match_deparment_code] => all
[sort_deparment_code] => ASC
[text_deparment_code] => aa
)
// Jquery将serialize字符串传递给ajax
function getInstantSearchResult(){
$('#keypress').keyup(function(){
var Post_String = $('#forma').serialize();
// ajax_get_data(1,st);
//alert(Post_String);
$.ajax({
type : 'POST',
url : 'jsonAjaxFinder.php',
data : {Query_String:Post_String},
success : function(value){
alert(value);
ajax_get_data(1);
}
});
});
}
function ajax_get_data(page){
var businessUnitRequest;
if (window.XMLHttpRequest)
{
businessUnitRequest=new XMLHttpRequest();
}
else
{
businessUnitRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
var frame = document.getElementById("frame");
frame.style.left='20px';
var paginations = document.getElementById("pagination");
businessUnitRequest.open("POST", "jsonAjaxFinder.php", true);
businessUnitRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
businessUnitRequest.onreadystatechange = function (){
if((businessUnitRequest.readyState == 4) && (businessUnitRequest.status=200))
{
frame = document.getElementById("frame");
var leng= frame.rows.length;
for (z = leng - 1; z > 0; z--){
frame.deleteRow(z);
}
var d = JSON.parse(businessUnitRequest.responseText);
for(var o in d){
var row = frame.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.style.paddingLeft='15%';
cell2.style.paddingLeft='1%';
cell1.innerHTML= d[o].department_code;
cell2.innerHTML= d[o].description;
}
}
}
businessUnitRequest.send('no_page='+parseInt(page));
//+'&serialize='+ serialize
businessUnitRequest.innerHTML="requesting....";
}
有人可以向我解释我的问题,因为我不知道如何解决它?该
答案 0 :(得分:0)
我不确定你在这里想要达到什么目的?
echo $search = $result['text_department_code'];
如果你想回应$ search是否匹配$ result [...],请执行以下操作:
echo $search == $result['text_department_code'];
如果你想在$ search中存储$ result并且回显它是否失败,你将不得不检查是否再次设置$ result [...]:
echo (isset($result['text_department_code']) && $search = $result['text_department_code']);
答案 1 :(得分:0)
查看您提供的var_dump并将其与您的代码进行比较。你有错别字......
print_r($result) output:
Array
(
[search_deparment_code] => department_code
[checkbox_deparment_code] => true
[match_deparment_code] => all
[sort_deparment_code] => ASC
[text_deparment_code] => aa
)
转储中有“Deparment”,数组索引中有“department”。
基本上,所有if(isset())行都返回false。
答案 2 :(得分:0)
我不确定这是否有帮助,但是在引用$result['text_department_code']
的if语句中,它应该是$text
if(!empty($search) && !empty( $checkbox) && !empty($match) && !empty($sort) && !empty($text))
{
echo $search = $text;
print $search;
print_r($result);
}