这似乎是来自不同语言的编码员的常见问题。
我正在使用jQuery将AJAX文本拉入屏幕,但是firebug报告了
unterminated string literal
有一个毫无价值的例子:
$("#content").html("<div class=\'grid_...g\'><\/div>\n<p>Cold Seafood Platters\n
我仔细检查了我的AJAX示例文本,如果有任何'
,它会以某种方式轰炸它,但我将它们全部删除,但它仍然无法解析。
之前有人遇到此错误并弄清楚如何处理它?</ p>
更新
调用此函数的助手:
def hq_nav_select(name, url)
if current_page? url
content_tag(:li, "<br /> #{link_to(sanitize(name, :tags => 'img'), url, :class => 'hq_nav_link')}", :class => 'selected')
else
content_tag(:li, "<br /> #{link_to(sanitize(name, :tags => 'img'), url, :class => 'hq_nav_link')}")
end
end
JS:
$(".hq_nav_link").live("click", function(){
$.ajax({type: "GET", url: $(this).attr("href"), dataType: "script"});
return false;
});
触发show.js.haml
== $("#content").html("#{ escape_javascript(render :partial => 'tab') }");
然后加载部分即最终文本
示例爆炸文字:
Cold Seafood Platters
<br />\r\nClassic Shrimp Cocktail
<br />\r\nThe shrimp that we are known for: large or jumbo, tender and tasty shrimp, steamed to order, beautifully arranged and garnished with our homemade cocktail sauce and lemon wedges.
Medium: Serves 8 – 6
<br />\r\nLarge: Serves 16 – 20
<br />\r\n<br />\r\nStone Crab Claws (Seasonal)
<br />\r\nDirect from Key West, Florida! Get them while you can! Garnished to impress and served with our homemade honey mustard sauce.
<br />\r\nLarge: Serves 8 - 10
<br />\r\n<br />\r\nMixed Seafood Royale
<br />\r\nThe platter to end all party platters! A generous offering of Lobster Meat, Jumbo Shrimp, and Cocktail Crab Claws, served with a trio of homemade dipping sauces.
<br />\r\nMedium: Serves 6 - 8
<br />\r\nLarge: Serves 12 - 15
<br />\r\n<br />\r\nPoached Salmon
<br />\r\nBeautiful and healthy as can be! Norwegian Salmon served with a homemade dill sauce.
<br />\r\nSide of Salmon $15.99/lb ( 3-4 lb.)
<br />\r\n<br />\r\nCedar Grilled Wild Salmon
<br />\r\nMakes a spectacular presentation! Wild West Coast Salmon glazed and grilled to perfection using a cedar grilling method.
<br />\r\nSide of Salmon: (4-5 lb)
<br />\r\n<br />\r\nSmoked Fish Platters
<br />\r\nSmoked Salmon
<br />\r\nThis platter comes garnished with sweet onion & tomato slices, capers and lemon wedges.
<br />\r\nSmall: Serves 6 – 8
<br />\r\nLarge: Serves 12 - 15
<br />\r\n<br />\r\nSmoked Fish Combo
<br />\r\nA gourmet feast of specialties! Our own Smoked Salmon, plus Sturgeon, Whitefish and Trout, lusciously arranged and complemented by sweet onion & tomato slices, capers and lemon wedges.
<br />\r\n<br />\r\nHerring in Wine & Herring in Cream
<br />\r\n<br />\r\nIced Seafood Platters
<br />\r\nImagine the freshest Oysters, Clams, Lobsters, Crab Claws... everything in a shell presented exquisitely on a platter at your next holiday gathering, office party or home event.
<br />\r\n<br />\r\nChoosing from: King Crab Legs, Jumbo Shrimp, Crab Claws, Scallops, Littleneck Clams, Caviar, New Zealand Mussels, Maine Lobster, and Stone Crab Claws (in season). Speak to one of our Freemans team members to determine the appropriate quantity and variety of shellfish for your celebration.
<br />\r\n<br />\r\nWe have catering partners who will cater your party with Freemans fresh seafood!
<br />\r\n<br />\r\nIndoor Clambakes
<br />\r\nExperience a taste of summer during the chill of winter. We supply a complete clambake in our convenient cooking tin, ready for your grill or stovetop. A Freemans specialty, it includes:
<br />\r\n
<br />\r\nTwo 1/4lb. lobsters, two ears of corn, red potatoes, steamers, two containers of New England or Manhattan chowder and our homemade garlic bread.
<br />\r\n<br />\r\nFish<br />\r\n• Alaskan White Salmon<br />\r\n• Arctic Char<br />\r\n• Baccala<br />\r\n• Black Bass<br />\r\n• Blowfish Tails<br />\r\n• Boned Shad/Shad Roe<br />\r\n• Carp<br />\r\n• Catfish<br />\r\n• Cod<br />\r\n• Farm Raised Salmon<br />\r\n• Flounder<br />\r\n• Grey Sole<br />\r\n• Lemon Sole<br />\r\n• Haddock<br />\r\n• Halibut<br />\r\n• Mahi Mahi<br />\r\n• Marlin<br />\r\n• Monkfish<br />\r\n• Rainbow Trout<br />\r\n• Red Snapper<br />\r\n• Salmon – Farmed & Wild<br />\r\n• Salmon Trout<br />\r\n• Spanish Mackerel<br />\r\n• Smelts<br />\r\n• Striped Bass<br />\r\n• Squid<br />\r\n• Swordfish<br />\r\n• Tilapia<br />\r\n• Tuna<br />\r\n• Whitefish<br />\r\n• Whiting<br />\r\n• Yellow Pike<br />\r\n<br />\r\nShellfish<br />\r\n• Backfin & Jumbo Lump Crab<br />\r\n• Crabmeat<br />\r\n• East Coast Oysters<br />\r\n• Littlenecks, Cherrystones & Minced Clams<br />\r\n• Live Blue Claws (seasonal)<br />\r\n• Live Dungeness Crabs<br />\r\n• Live Maine Lobsters<br />\r\n• Medium, Large & Jumbo Shrimp<br />\r\n• New Zealand Mussels<br />\r\n• Prince Edward Island Mussels<br />\r\n• Scallops (Sea, Bay, Diver & Nantucket)<br />\r\n• Soft Shell Crabs (seasonal)<br />\r\n• Steamers • Wellfleet Oysters<br />\r\n<br />\r\nFrozen<br />\r\n• Alaskan King Crab Legs<br />\r\n• Alligator Meat<br />\r\n• Brazilian Lobster Tails<br />\r\n• Cleaned Squid<br />\r\n• Crawfish Meat<br />\r\n• Lobster Meat<br />\r\n• Louisiana Crawfish Tails<br />\r\n• Orange Roughy<br />\r\n• Pulpo<br />\r\n• Snow Crab Claws<br />\r\n<br />\r\n<br />\r\nSeafood Salads and Buffet Platters
<br />\r\nSeafood Salads
<br />\r\nA fine selection of homemade specialty salads. Available a la carte or by the pound. Tastefully presented on catering trays at your request.<br />\r\n<br />\r\n• Baccala Salad<br />\r\n• Calamari Salad<br />\r\n• Frutta Di Mare<br />\r\n• Lobster Salad<br />\r\n• Shrimp Salad<br />\r\n• Mixed Seafood Salad<br />\r\n• Fresh Salmon Salad<br />\r\n• Fresh Tuna Salad<br />\r\n• Smoked Salmon Salad<br />\r\n• Smoked Whitefish Salad<br />\r\n<br />\r\nLuncheon – Dinner
<br />\r\nOur most popular lunch and dinner entrées. Available a la carte, individually or by the pound. Tastefully presented on platters at your request.<br />\r\n<br />\r\n• Cedar Grilled Salmon<br />\r\n• Codfish Cakes<br />\r\n• Crawfish Cakes<br />\r\n• Fried Tilapia<br />\r\n• Flounder Français<br />\r\n• Jumbo Lump Crabcakes<br />\r\n• Lobster Rolls<br />\r\n• Poached Salmon<br />\r\n• Tuna Sandwich<br />\r\n• Fresh Steamed Shrimp<br />"
答案 0 :(得分:1)
如果您只需要文字或HTML,请更改dataType:
$.ajax({type: "GET", url: $(this).attr("href"), dataType: "html"}); // for HTML
$.ajax({type: "GET", url: $(this).attr("href"), dataType: "text"}); // for raw text
否则jQuery会将响应评估为JavaScript(来自http://api.jquery.com/jQuery.ajax/)。在这种情况下,您可能需要dataType:“html”来自Rails content_tag。
更新:尝试使用快捷方式版本,这也会写入#content元素:
$.get($(this).attr('href'), function(response) { $('#content').html(response); });