News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

CouchMoney javascript creating syntax error

Started by SlyBaldGuy, December 27, 2018, 12:48:12 AM

Previous topic - Next topic

SlyBaldGuy

I've signed up to use CouchMoney.net to convert words and phrases to affiliate links and I'm getting a syntax code when I place the javascript above the closing HEAD tag in the index.template.php file of my theme.

Here's the code:


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script>
      $.ajax({
          url: "https://couchmoney.net/api/1.1/obj/script?constraints=%5B%7B%20%22key%22%3A%20%22websiteid%22%2C%22constraint_type%22%3A%20%22equals%22%2C%22value%22%3A%20%221542831846810x186262284968394750%22%7D%2C%7B%22key%22%3A+%22valid%22%2C%22constraint_type%22%3A+%22equals%22%2C%22value%22%3A+%22yes%22%7D%5D",
          success: function(data){
            $str = '';
            $str = (data['response'].results[0]['script']);
            $str = $str.replace("\n", "", "g");
            var F=new Function ($str);
            return(F());
          }
        });
</script>

</head>


Here's the syntax error that I'm receiving:

QuoteParse error: syntax error, unexpected '';' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in .../Themes/OrangeCrush/index.template.php on line 180

Can anyone tell me how to modify the script to work?

I'm on 2.0.14 and PHP 5.6

Aleksi "Lex" Kilpinen

Try this


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script>
      $.ajax({
          url: "https://couchmoney.net/api/1.1/obj/script?constraints=%5B%7B%20%22key%22%3A%20%22websiteid%22%2C%22constraint_type%22%3A%20%22equals%22%2C%22value%22%3A%20%221542831846810x186262284968394750%22%7D%2C%7B%22key%22%3A+%22valid%22%2C%22constraint_type%22%3A+%22equals%22%2C%22value%22%3A+%22yes%22%7D%5D",
          success: function(data){
            $str = \'\';
            $str = (data[\'response\'].results[0][\'script\']);
            $str = $str.replace("\n", "", "g");
            var F=new Function ($str);
            return(F());
          }
        });
</script>


Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF


Aleksi "Lex" Kilpinen

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

SlyBaldGuy

To update this should anyone else decide to use CouchMoney, I realized I could just paste the original code into the Custom Head and Body Scripts mod without needing to modify the code. I highly recommend this mod if you run extra scripts within your site.

Advertisement: