2014-12-02 1 views
4

나는 다음과 같은 코드를 가진 DataTables 인스턴스를 시작하려고 해요로 대체되고 ...

<script type="text/javascript" language="javascript" class="init"> 
$(document).ready(function() { 
     $('#example').DataTable(); 
}); 
</script> 

을하지만 웹 통하여, HTML에 액세스 할 때 브라우저는 "catch되지 않은 구문 에러 : 예기치 않은 번호"이다 ... 오류를이 소스 브라우저에서 모습입니다

<script type="text/javascript" language="javascript" class="init"> 
0 11 4 3 2 1 0document).ready(function() { 
    0 11 4 3 2 1 0'#example').DataTable(); 
}); 
</script> 

당신은 몇 가지 지침이 숫자 "0 11 4 세에 의해 대체되었습니다 볼 수 있듯이 2 1 "나는 그것이 무엇을 일으키는 지 모른다.

jQuery는 Google의 src이고 DataTables는 해당 CDN의 자바 스크립트입니다.

CGI를 사용하여 Perl 스크립트에서 HTML을 만들고 Content-type : text/html 헤더를 인쇄하고 다른! DOCTYPE을 사용했습니다.하지만 여전히 아무것도 아닙니다. 코드를 편집하면 숨겨진 문자가 표시되지 않습니다.

귀하의 도움을 많이 주시면 감사하겠습니다.

최고, e.

편집 :

$(document).ready(function() { 
     $('#example').DataTable(); 

에 따르면이

use Switch; 
use CGI qw/:standard/; 
use CGI::Carp 'fatalsToBrowser'; 

print "Content-type:text/html\r\n\r\n"; 

print qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0"> 
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> 
<script language="JavaScript" type="text/javascript" src="js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" language="javascript"> 
/* <![CDATA[ */ 
$(document).ready(function() { 
     $('#example').DataTable(); 
}); 
/* ]]> */ 
</script> 
</head>}; 
+0

init 클래스는 무엇을합니까? –

+0

HTML을 생성하는 Perl 코드를 보여주십시오. – ThisSuitIsBlackNot

+0

@ Bhojendra-C-LinkNepal 잘 모름, 모든 시도 중 하나이지만 원본 DataTables 예제 파일 중 하나에 있습니다. – Emiliano

답변

4

문제는 qq 변수를 보간하여 HTML 문자열이 특수 변수 $( 포함입니다 ... HTML을 생성하는 펄 코드 perldoc perlvar :

$(

The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid() , and the subsequent ones by getgroups() , one of which may be the same as the first number.

문자열에있는 $(의 각 항목이 웹 서버 사용자가 속한 GID 목록으로 바뀝니다.

명령 줄에서이 작업을 볼 수 있습니다

perl -wE 'say qq{$(document).ready(function()}' 

출력 내 시스템에

3000 3000document).ready(function() 

.

대신 q을 사용하면 Perl 변수로 보간하는 것을 피할 수 있습니다.

+2

양자 택일로, 만약 당신이 실제로 어떤 변수를 보간하기를 원한다면, 변수를 시작하지 않는 모든'$'를 벗어나십시오. (예를 들어'\ $ (document) .ready') – ysth

+0

jQuery onReady, 어쨌든'jQuery (function (jQ) {...')와 같은 것으로해야 할 것입니다. 그럼'$'를 사용했을 때마다'jQ'를 사용하십시오. – Ashley

+0

@Ashley 그런 JavaScript 코드를 배척하기 시작하면 아마 별도의 정적 파일에 넣거나 [Template Toolkit] (http://www.template-toolkit.org/)과 같은 템플릿 시스템을 사용하십시오. – ThisSuitIsBlackNot

관련 문제