【问题标题】:Jquery error sending hex code through getJquery错误通过get发送十六进制代码
【发布时间】:2014-04-08 15:36:03
【问题描述】:

下面是我的代码...

var o_color ='<?php echo $o_color;?>'; //i have also tried urlencode($o_color)
var o_color1 ='';

这段代码运行良好....

   window.location.href = site+"name="+$(this).attr('id')+'&o_color='+o_color;

但是这段代码不起作用....

   window.location.href = site+"name="+$(this).attr('id')+'&o_color='+o_color+'&o_color1='+o_color1;

Note:o_color is in hexa code #e34343;

我在控制台日志中收到一条 jquery 错误消息...

Uncaught Error: Syntax error, unrecognized expression: a[rel=123123&o_color1=] 

【问题讨论】:

    标签: javascript php jquery colors get


    【解决方案1】:

    尝试删除"o_color"中的双引号

    window.location.href = site+"name="+$(this).attr('id')+'&o_color='+ o_color +'&o_color1='+o_color1;
    

    据此你必须是:-

    <script>
    var site='http://localhost/new/';
    var o_color = '#e34343';
    var o_color1 = '';
    window.location.href = site+'name=dfg&o_color='+o_color+'&o_color1='+o_color1;
    </script>
    

    【讨论】:

    • 对不起,我刚刚更新了正确的代码.. 我已经尝试删除 "" 引号......我正在通过插入 "" 进行测试,我错误地更新了该代码...... ...两个代码都不起作用....
    • 尝试只使用引号' 或双引号" 来包装您的查询字符串。目前你正在混合这两者。另外,您确定语法错误发生在上面的行吗?
    • 刚才我在地址栏上尝试了window.location.href = site+'?font_name='+$(this).attr('id')+'&amp;o_color='+ o_color +'&amp;o_color1='+o_color1;,我看到www.example.com?font_name=Alpha_Mack&amp;o_color=#e30456&amp;o_color1=,但在cosole错误我看到Uncaught Error: Syntax error, unrecognized expression: a[rel=e30456&amp;o_color1=] :(
    • 那么url 是正确的吗?该错误可能来自其他行 IMO
    • 是的,即使我也有同样的感觉......让我用其他页面代码更新我的问题,,,
    【解决方案2】:

    试试

    window.location.href = site+"name="+$(this).attr('id')+"&o_color="+o_color+"&o_color1="+o_color1;
    

    根据你的情况

    <script>
    var site='http://localhost/new/';
    var o_color = '#e34343';
    var o_color1 = '';
    window.location.href = site+'name=dfg&o_color='+o_color+'&o_color1='+o_color1;
    </script>
    

    【讨论】:

    • 对不起,我刚刚更新了正确的代码.. 我已经尝试删除 "" 引号......我正在通过插入 "" 进行测试,我错误地更新了该代码......
    • 当我得到 felix 的明确回应“所以 url 是正确的?错误可能来自其他行 IMO – Felix”我已经接受了他的回答.. 无论如何,非常感谢我的尝试你的答案.. :)
    猜你喜欢
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2017-02-13
    • 2014-05-15
    • 1970-01-01
    相关资源
    最近更新 更多