Home  >  Article  >  Backend Development  >  CI框架中使用ajax操作数据库有关问题

CI框架中使用ajax操作数据库有关问题

WBOY
WBOYOriginal
2016-06-13 12:10:25924browse

CI框架中使用ajax操作数据库问题

本帖最后由 A9925 于 2014-11-24 16:11:05 编辑 前台:
<script><br />//调用方法用ajax操作add_dbdata.php<br />var xmlHttp<br />function add_dbdata(str,str1){<br />		<br />	//alert(str);<br />	if (str=="")<br />	{<br />	document.getElementById("txtHint").innerHTML="";<br />	return;<br />	}<br />	if (window.XMLHttpRequest)<br />	{// code for IE7+, Firefox, Chrome, Opera, Safari<br />	xmlhttp=new XMLHttpRequest();<br />	}<br />	else<br />	{// code for IE6, IE5<br />	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");<br />	}<br />	xmlhttp.onreadystatechange=function()<br />	{<br />	if (xmlhttp.readyState==4 && xmlhttp.status==200)<br />	{<br />	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;<br />	}<br />	}<br />	//xmlhttp.open("GET","add_dbdata.php?q="+str,true);<br />	//alert(str1);<br />	//alert(str);<br />	<br />	xmlhttp.open("GET","add_dbdata.php?q="+str,true);	   //xmlhttp.open("GET","<?=base_url()?>project_c/add_zijiedian/"+str1+str,true);  这样写,也不好使,不知道哪有问题 <br />	xmlhttp.send();<br />}


后台操作数据库

<br /><?php<br />header("Content-type:text/html;charset=utf8");<br />$q=$_GET["q"];<br />$q=(int)$q;<br />echo "<script>alter('kkkkkkk');</script> ";<br /><br /><br />$con = mysql_connect('localhost', 'root', '');<br />if (!$con)<br /> {<br /> die('Could not connect: ' . mysql_error());<br /> }<br /><br />mysql_select_db("test", $con);<br />mysql_query("set names utf8");<br /><br />//$sql = " SELECT * FROM ecm_acategory ";<br />$sql = " insert into data (name) values('999')";<br />echo $sql;<br />$result = mysql_query($sql);<br /><br /><br />mysql_close($con);<br />?><br /><br />



求助, 本地测试不用CI,这样写没问题,加个CI,上边的路径换了几种也不好使,不知道怎么回事。 先谢谢了!

------解决思路----------------------
那不是乱码,而是 url 编码
入库前先解码(urldecode)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn