2016-06-24 3 views
0

왜이 함수에서 루트 경로가 두 배가됩니까? 여기 jQuery가 load() 함수에서 루트 경로를 두배로 늘림

function bodyClass(id) { 
 
    var catName = $('#location').children().eq(4).text(), 
 
     rootPar = ("http://localhost/site/" + catName), 
 
     banner = $('#wantedDiv'), 
 
     
 
     // this load variable doubles up the root path and does not escape the first single quote 
 
     content = $('<div />').load("'" + rootPar + " " + banner + "'", function(){ 
 
     $('#placeDiv').prepend(content.html()); 
 
     }); 
 
     
 
     // console logging retrieves the correct path inclusing the added "catName" 
 
     console.log(rootPar); 
 

 
} 
 
bodyClass();
브라우저 콘솔이 날을 표시 내용은 다음과 같습니다

CONSOLE.LOG : http://localhost/site/page

부하() FUNC : GET http://localhost/site/ 'http://localhost/site/page' 404 (하지 않음 찾음)

답변

2

페이지가로드되면 http://localhost/site/으로로드되므로 루트 웹 페이지를 다시 추가하면 이미있는 페이지에 추가됩니다. 난 그냥 catName 대신에 추가 할 것입니다 rootPar

+0

function bodyClass(id) { var catName = $('#location').children().eq(4).text(), rootPar = (catName + "/ "), banner = "'" + '#' + 'wantedDiv' + "'", content = $('<div />').load(rootPar + banner, function(){ $('#placeDiv').prepend(content.html()); }); } bodyClass();

나는 이미없는 행운을 수행했습니다. 이것은 http : // localhost/site/'페이지/404 (찾을 수 없음) -> 첫 번째 작은 따옴표를 이스케이프 처리하지 않는 오류입니다. – Sergio

+0

작은 따옴표를 모두 제거하면 어떻게됩니까? –

+0

다른 오류가 발생합니다.> 인식 할 수없는 표현식 : [object Object] ' – Sergio

0

비슷한 해결책을 찾고있는 누군가를 위해. 연결을 load() 함수가 아니라 변수로 옮겼습니다.

관련 문제