When we pass the path with Ajax, it is possible to make mistakes, especially when there are characters in the path, and the path is different from the received path. Workaround: Encode the path at the time of passing the path and decode it to the database when it is received.
Such as:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Scripttype= "Text/javascript"src=".. /jquery-1.11.2.min.js "></Script></Head><Body><imgsrc= "img/fruit. jpg"ID= "Tupian" /><BR/></Body></HTML><Scripttype= "Text/javascript">$ (document). Ready (function(e) {varURL= $("#tupian"). attr ("src"); varlujing= encodeuricomponent(URL);//URL encoding //alert (lujing);$.ajax ({URL:"chuli.php", data:{url:lujing}, type:"POST", DataType:"TEXT", Success:function(data) {//alert (data); if(Data.trim ()=="OK") {alert ("Add success! "); } Else{alert ("Add failed! "); } } });});</Script>
Handling page chuli.php:
<?PHP$url=$_post["url"];$lujing=UrlDecode($url);//URL decodinginclude(".. /db.class.php ");$db=NewDB ();$sql= "INSERT into nation values (' n014 ', ' {$lujing}‘)";if($db->query ($sql, 1)){ Echo"OK"; }Else{ Echo"NO"; }
Ajax address URL encoding format