zoukankan      html  css  js  c++  java
  • Thinkphp Ajax传地址

    在使用文本编辑器时,如果加入图片,涉及到图片的src,需要用到Ajax传地址到处理页面。

    在使用Ajax的过程中,如果要通过JSON传递路径值到处理页面,会出现传值不正确。

    解决方法就是在传值之前将路径进行编码:

    encodeURIComponent(url)

    在处理页面,将接收到的路径变量进行解码:

    urldecode(url)

    例如:

    text.html

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="../../jquery-1.11.2.min.js"></script>
    </head>
    
    <body>
    <img src="/www/all/0704/20150619101413701.jpg" id="img" />
    </body>
    <script type="text/javascript">
    $(document).ready(function(e) {
    	var url = $("#img").attr("src");
    	//编码
    	var lujing = encodeURIComponent(url);  
    	//alert(url);
        $.ajax({
    		url:"chuli.php",
    		data:{url:lujing},
    		type:"POST",
    		datatype:"TEXT",
    		success: function(data){
    			//alert(data);
    			
    			}
    		});
    });
    </script>
    </html>
    

     chuli.php

    <?php
    $url = $_POST["url"];
    //解码
    $lujing = urldecode($url);
    
    include("../../DBDA.class.php");
    $db = new DBDA();
    $sql = "insert into nation values('s03','{$lujing}')";
    $db->Query($sql,1);
    

      

  • 相关阅读:
    第一个SWT程序
    稀疏数组
    算法与数据结构
    《Java核心技术》学习笔记 第1-3章
    算术运算符
    5.11 rw zip file
    5.10 gob序列化
    5.9 piping between writer and reader
    5.7 io.MultiWriter(buf, f)
    5.7 读写 二进制数据
  • 原文地址:https://www.cnblogs.com/ds-3579/p/5640343.html
Copyright © 2011-2022 走看看