为什么我的搜索代码在Internet Explorer上不起作用 [英] why my search code does not work on internet explorer

查看:107
本文介绍了为什么我的搜索代码在Internet Explorer上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码从数据库显示返回结果到页面,并显示它们与jqgrid,我的代码与Firefox正常工作,但它不工作,即当我使用utf8
像阿拉伯文字母,我将ie和firefox的编码设置为unicode(utf8)

其html代码

 名字:< input type =textid =firstnameonkeydown =doSearch(arguments [0] || event)value =class =mytextbox/> 

< button onclick =gridReload()id =submitButtonstyle =margin-right:100px;类= 按钮 >搜索和LT; /按钮>

我的javascript代码

  function gridReload(){
var name = jQuery(#firstname)。val();

jQuery(#list2)。jqGrid('setGridParam',{url:<?php bloginfo('template_url');?> /post2.php?firstname =+ firstname ,page:1})。trigger(oadGrid);

}

和我的php代码

  if(isset($ _ GET [firstname]))
$ firstname = $ _GET ['firstname'];

mysql_query(set names utf8);

if($ firstname!='')
$ where = firstname LIKE'$ firstname%';

$ SQL =SELECT id,firstname,lastname FROM mytable。$ where。
ORDER BY $ sidx $ sord LIMIT $ start,$ limit;

$ result = mysql_query($ SQL)或die(mysql_error());
$ responce-> ; page = $ page;
$ responce-> total = $ total_pages;
$ responce-> records = $ count;
$ i = 0;
while($ row = mysql_fetch_array($ result,MYSQL_ASSOC)){
$ responce-> rows [$ i] ['id'] = $ row [id];
$ responce-> rows [$ i ] ['cell'] = array(
$ row [id],$ row [firstname],$ row [lastname]);
$ i ++;
}

echo json_encode($ responce);

为什么它不适用于ie(我用ie8测试)但与opera和firefox一起工作



谢谢 首先你在使用 setGridParam 的行中有引号的问题。可能你的意思是

  jQuery(#list2)。jqGrid('setGridParam',
{url:<?php bloginfo('template_url');?> /post2.php?firstname =+ fir tname,
page:1})。trigger(reloadGrid);

而不是

  jQuery(#list2)。jqGrid('setGridParam',
{url:<?php bloginfo('template_url');?> /post2.php?firstname =+第一名,
page:1})。trigger(oadGrid);

在我看来,使用这段代码建立url不是很好,你至少应该使用类似于
$ b

  jQuery(#list2) .jqGrid('setGridParam',
{url:<?php bloginfo('template_url');?> /post2.php?firstname =
+ encodeURIComponent(firstname),$ b $ (reloadGrid);

  jQuery(#list2)。jqGrid('setGridParam',
{url:<?php bloginfo('template_url')) ;?> /post2.php?+
jQuery.param({firstname:firstname}),
page:1})。trigger(oadGrid);

然后来自 firstname 的任何国际字符将会b e在URL中正确编码。



另一种方法是使用jqGrid的 postData 参数。参见例如,如何过滤不使用内置的搜索/过滤器框的jqGrid数据。


i have the following code for search from database show return result to the page and show them with jqgrid, my code works fine with firefox but its not work on ie, when i use of utf8 like arabic letters, i set both of encoding of ie, and firefox to unicode(utf8)

its html code

first name: <input type="text" id="firstname" onkeydown="doSearch(arguments[0]||event)" value="" class="mytextbox" /> 

<button onclick="gridReload()" id="submitButton" style="margin-right:100px;" class="Buttons">search</button> 

my javascript code

function gridReload(){ 
    var name = jQuery("#firstname").val();

jQuery("#list2").jqGrid('setGridParam',{url:"<?php bloginfo('template_url'); ?>/post2.php?firstname="+firstname",page:1}).trigger("reloadGrid");

}

and my php code

if(isset($_GET["firstname"]))
 $firstname = $_GET['firstname'];

mysql_query ( "set names utf8" );

if($firstname!='')
 $where= "  firstname LIKE '$firstname%'"; 

$SQL = "SELECT id,firstname,lastname FROM  mytable ".$where." 
     ORDER BY $sidx $sord LIMIT $start , $limit";

 $result = mysql_query( $SQL ) or die(mysql_error());
$responce->page = $page;
     $responce->total = $total_pages;
     $responce->records = $count;
 $i=0;
 while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { 
     $responce->rows[$i]['id']=$row[id];
     $responce->rows[$i]['cell']=array(
     $row[id],$row[firstname],$row[lastname]);
     $i++; 
     }

 echo json_encode($responce); 

why its not work with ie(i teste with ie8) but works with opera and firefox

thanks

解决方案

First of all you have problem with quotes in the line where you use setGridParam. Probably you mean

jQuery("#list2").jqGrid('setGridParam',
    {url:"<?php bloginfo('template_url'); ?>/post2.php?firstname="+firstname,
     page:1}).trigger("reloadGrid");

instead of

jQuery("#list2").jqGrid('setGridParam',
    {url:"<?php bloginfo('template_url'); ?>/post2.php?firstname="+firstname",
     page:1}).trigger("reloadGrid");

It seems to me not good to build url with this code. You should at least use something like

jQuery("#list2").jqGrid('setGridParam',
    {url:"<?php bloginfo('template_url'); ?>/post2.php?firstname="
         +encodeURIComponent(firstname),
     page:1}).trigger("reloadGrid");

or

jQuery("#list2").jqGrid('setGridParam',
    {url:"<?php bloginfo('template_url'); ?>/post2.php?"+
         jQuery.param({firstname: firstname}),
     page:1}).trigger("reloadGrid");

Then any international characters from the firstname will be encoded correctly in the url.

One more way is the usage of postData parameter of the jqGrid. See How to filter the jqGrid data NOT using the built in search/filter box for example.

这篇关于为什么我的搜索代码在Internet Explorer上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆