Reputation: 105
I have been trying to solve this but can't get it to work.
http://tinyurl.com/973he2p **the html is supposed to go into another page so I don't have access to html, body header tags.
The content is on the right side under the heading "You May Also Like", and that content loads from this file http://tinyurl.com/8rv36dl
But I have seen and it fails to load 3 out of 10 times. So I refreshed it and that really happens. What could be the reason?
What am I doing wrong or what should I be doing to fix it? conflicts? time outs? I have tried it all.
hope to have an answer.
Upvotes: 0
Views: 57
Reputation: 15552
When you generate the showitem.js
you create a variable named content
and assign a value to it enclosed by apostrophes, but you don't escape the apostrophes in the content, like in this occasion:
var content = '...<div class="caption_plc">Men's Costume...
^
The apostrophe here closes the value assignment to content
immediately followed by the string s Costume...
which cannot be interpreted in Javascript, so the following error is triggered on line 2:
Uncaught SyntaxError: Unexpected identifier
Maybe on a few cases there are no apostropes at all in the content, and your code works, but when there is, it fails. So escape at least the apostrophes, or encode the content into a JSON.
Upvotes: 1
Reputation: 27307
The apostrophe in men's stainless steel bracelet
(or whatever is inserted by the server) closes the string opened by var content= ' ...
in showitem.js
and causes a syntax error.
You need to properly escape the content generated by the server before including it in the generated javascript.
The best way, however, would be to have a static javascript file, untouched by PHP, and let it fetch its contents via AJAX. Since you are already using jQuery, read up on $.get
Upvotes: 1