Help !! Php + ajax + json question this post was last edited by zl2727 at 18:08:23
function gtou($s) { return iconv('gbk', 'utf-8', $s); }$proquery ="select * from pro where typeid='".$id."' order by corank asc"; $dsql->SetQuery($proquery); $dsql->Execute(); $a=array(); while($row = $dsql->GetArray()) { $a[]= array_map('gtou', $row); } $res = array( "status" => "1", "result" => $a, "moreUrl" => $moreurl, ); echo json_encode($res);
The returned value is {"status": "1", "result": [], "moreUrl": "http: \/wcn"}. The result is null.
If
Echo json_encode ($ res );
Change to the following
// Echo '{"status": "1", "result": [{"id": "1", "typeid": "111", "goodstitle ": "\ u8865 \ u6c34 \ u6da6 \ u80a4 \ u818f \ Alibaba \ u7684 \ Alibaba \ u597d \ Alibaba \ u8865 \ Alibaba \ u76ae \ u80a4 \ u6709 \ u5f39 \ u6027 ", "goodsurl": "http: \/www. \/uploads \/allimg \/c131205 \/13V23912150-114L_lit.jpg "," brandtitle ":" \ u7f8e \ u5b9d \ u83b2 "," brandurl ":" http :\// www. \/dsadasdas \/"," imgurl ":" http: \/www. \/sadas213 \/"," price ":" 59.9 "," corank ":" 1 "},{" id ":" 2 "," typeid ": "111", "goodstitle": "\ u8865 \ u6c34 \ u6da6 \ u80a4222", "goodsurl": "http: \ // www. \/uploads \/allimg \/c131205 \/13V23912150-114L_lit.jpg "," brandtitle ":" \ u7f8e222 "," brandurl ":" http: \ // www. \/dsadasdas \/"," imgurl ":" http: \/www. \/sadas213 \/"," price ":" 59.9 "," corank ":" 1 "}]," moreUrl ":" http: \/jianfei. \/shuiguo \/"} '; that's correct. Please help the moderators and instruct them again.
Reply to discussion (solution)
Output with var_dump
Print_r ($ a); check out
Array ([0] => Array ([id] => 1 [goodstitle] => ユ ???? ??? Atlas? Why? Too many? ????? Ridge ?? [Goodsurl] => http://www.ecoo.com.cn/uploads/allimg/c131205/13V23912150-114L_lit.jpg [brandtitle] => ???? [Brandurl] => http://www.ecoo.com.cn/dsadasdas/ [imgurl] => http://www.ecoo.com.cn/sadas213/ [price] => 59.9) [1] => Array ([id] => 2 [goodstitle] => ユ ?? 222 [goodsurl] => http://www.ecoo.com.cn/uploads/allimg/c131205/13V23912150-114L_lit.jpg [brandtitle] =>? 222 [brandurl] => http://www.ecoo.com.cn/dsadasdas/ [imgurl] => http://www.ecoo.com.cn/sadas213/ [price] => 59.9 ))
This is the result of var_dump.
Array (2) {[0] => array (7) {["id"] => string (1) "1" ["goodstitle"] => string (54) "ユ ???? ??? Atlas? Why? Too many? ????? Ridge ?? "[" Goodsurl "] => string (70)" http://www.ecoo.com.cn/uploads/allimg/c131205/13V23912150-114L_lit.jpg "[" brandtitle "] => string (9)" ???? "[" Brandurl "] => string (33)" http://www.ecoo.com.cn/dsadasdas/ "[" imgurl "] => string (32)" http://www.ecoo.com.cn/sadas213/ "[" price "] => string (4) "59.9"} [1] => array (7) {["id"] => string (1) "2" ["goodstitle"] => string (15) "Why ?? 222 "[" goodsurl "] => string (70)" http://www.ecoo.com.cn/uploads/allimg/c131205/13V23912150-114L_lit.jpg "[" brandtitle "] => string (6)"? 222 "[" brandurl "] => string (33)" http://www.ecoo.com.cn/dsadasdas/ "[" imgurl "] => string (32) "http://www.ecoo.com.cn/sadas213/" ["price"] => string (4) "59.9 "}}
No. $ a is not empty and no empty array is output.
Can you add me to the moderator? I will send you a test connection.
I replace $ a
$ A = array ("id" => "1102444", "title" => "in fact", "goodstitle" => "in fact ", "price" => "429.0", "imgurl" => ". jpg "," goodsurl "=>"/"," brandtitle "=>" 44444 "," brandurl "=>" _ share /"), array ("id" => "1102444", "title" => "gambling hosts", "goodstitle" => "gambling hosts", "price" => "429.0 ", "imgurl" => "0.jpg"," goodsurl "=>" 2444/"," brandtitle "=>" 7777 "," brandurl "=>" share /"));It is also correct. the result that can be received at the front end is not empty.
Is the database problem you said when reading data can also turn how to UTF-8? I have been searching for a long time
My table is a GBK table. neither can I create a new UTF-8 table.
$ A is in the function. have you called it. Is the return function incorrect?
Thank you for your support.
Path error during AJAX request
No other problems
Close the post !!!
Function gtou ($ s) {return iconv ('gbk', 'utf-8', $ s );} $ a = array ("id" => "1102444", "title" => "in fact", "goodstitle" => "in fact ", "price" => "429.0", "imgurl" => ". jpg "," goodsurl "=>"/"," brandtitle "=>" 44444 "," brandurl "=>" _ share /"), array ("id" => "1102444", "title" => "gambling hosts", "goodstitle" => "gambling hosts", "price" => "429.0 ", "imgurl" => "0.jpg"," goodsurl "=>" 2444/"," brandtitle "=>" 7777 "," brandurl "=>" share /")); foreach ($ a as $ r) $ t [] = array_map ('gtou', $ r); $ moreurl = 'x '; $ res = array ("status" => "1", "result" => $ t, "moreUrl" => $ moreurl,); echo json_encode ($ res );{"Status": "1", "result": [{"id": "1102444", "title": "\ u4e8b \ u5b9e \ u4e0a", "goodstitle ": "\ u4e8b \ u5b9e \ u4e0a", "price": "429.0", "imgurl ":". jpg "," goodsurl ":" \/"," brandtitle ":" 44444 "," brandurl ":" _ share \/"},{" id ": "1102444", "title": "\ u8d4c \ u4e1c \ u9053 \ u7684", "goodstitle": "\ u8d4c \ u4e1c \ u9053 \ u7684", "price ": "429.0", "imgurl": "0.jpg"," goodsurl ":" 2444 \/"," brandtitle ":" 7777 "," brandurl ": "share \/"}], "moreUrl": "x "}
No problem. check whether your query conditions are correct!
If no query is found, it is naturally an empty array.