【问题标题】:Get Php String in jquery variable在 jquery 变量中获取 PHP 字符串
【发布时间】:2018-10-15 18:22:01
【问题描述】:

我想在 jquery 变量中跟踪 php 字符串

{
'05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Seeing dads differently</a>',
'05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Extraordinary ordinary Britain</a>',
'05-10-2018' : '<a href='http:www.google.com/' target='_blank'> Roll up for the Social Science Market!</a>',
'05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Why do we use it?</a>',
'05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Extraordinary ordinary Britain</a>'
}

【问题讨论】:

  • 这个问题需要认真改写...
  • 这是 php json 字符串吗?
  • 我想要劳斯莱斯幻影。
  • 不是 json 它的简单 php 字符串

标签: javascript php jquery ajax codeigniter


【解决方案1】:

试试这个代码。

<?php
    $phpstring = "{'05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Seeing dads differently</a>','05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Extraordinary ordinary Britain</a>','05-10-2018' : '<a href='http:www.google.com/' target='_blank'> Roll up for the Social Science Market!</a>',
    '05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Why do we use it?</a>','05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Extraordinary ordinary Britain</a>'}";
    $phpstring = json_encode($phpstring);

    echo "<script> var TestVar = $phpstring;</script>";
?>

【讨论】:

  • @u_mulder,她说这是简单的 php 字符串而不是 json。
  • var Events = { '10-17-2018' : 'google.com" target=_blank>Eaque molestiae assumenda necessitatibus alias dignissimos quod facere!', ' 09-22-2018' : 'google.com" target=_blank>Quo accusamus itaque esse aliquid error reprehenderit!', };我想在 jquery 中使用它。当我警告该变量时,我应该在警报中获取对象对象
  • var 事件 = { '10-17-2018' : 'Eaque molestiae assumenda necessitatibus alias dignissimos quod facere!', '09-22-2018' : 'Quo accusamus itaque esse aliquid error reprehenderit!', };我想在 jquery 中使用这个。当我提醒该变量时,我应该在警报中获取 [object Object]
  • 你说是简单的php字符串,那你怎么得到对象呢?
【解决方案2】:

您可以在 jquery 中使用 php variale,例如:

<script type="text/javascript">
    var php_string;
    php_string = "<?= $phpstring ?>";
</script>

【讨论】:

    猜你喜欢
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2010-09-20
    • 2022-10-21
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多