2016-11-30 3 views
0

html로 html 코드를 삽입하고 다른 모든 버튼이 sqlite 데이터베이스에 데이터를 보내는이 태평양 버튼을 사용하더라도 다음 오류가 발생합니다.오타가있는 코드를 삽입 할 때 구문 오류가 발생할 수 있습니까?

catch되지 않은 구문 에러 :

문제 인수 목록 뒤에)가 없습니다 나는 코드를 검토하고 다양한 접근과 시도했습니다에만 포인트 DOCTYPE에 무슨 잘못이 늘 잡을 코드를 주입 ​​메신저 이후?

되는 HTML

주입되고 :

$(info).html('<h4 class="media-heading">' + response[rCnt].title + '</h4><h3><span class="glyphicon glyphicon-star" aria-hidden="true"> </span> ' + response[rCnt].social_rank.toFixed(2) + '</h3><h3><span class="glyphicon glyphicon-print" aria-hidden="true"> </span> ' + response[rCnt].publisher + '</h3><h3><span class="glyphicon glyphicon-home" aria-hidden="true"> </span> <a> ' + response[rCnt].source_url + '</a></h3><button type="button" class="btn btn-default" id="button1" onclick="saveRecipe(' + response[rCnt].title + ',' + response[rCnt].social_rank.toFixed(2) + ',' + response[rCnt].publisher + ',' + response[rCnt].source_url + ')" title="Save"><span class="glyphicon glyphicon-save" aria-hidden="true"></span></button>'); 

HTML 버튼 내부의 쉽게 읽을 수 있도록 :

<button type="button" class="btn btn-default" id="button1" onclick="saveRecipe(' + response[rCnt].title + ',' + response[rCnt].social_rank.toFixed(2) + ',' + response[rCnt].publisher + ',' + response[rCnt].source_url + ')" title="Save"><span class="glyphicon glyphicon-save" aria-hidden="true"></span></button> 

되는 HTML 버튼에 데이터를 제공하는 AJAX 호출 :

function saveRecipe(title, rank, auth, src) { 
    $.ajax({ 
     type: "POST", 
     headers: { 
      "Content-Type": "application/json" 
     }, 
     url: "/SaveFile", 
     data: JSON.stringify({ 
      name: title, 
      rating: rank, 
      author: auth, 
      source: src 
     }), 
     success: function(response) { 
      console.log("Hii"); 
      console.log(response); 
     }, 
     error: function(response, error) { 
      console.log(response); 
      console.log(error); 
     } 
    }); 
} 
+0

버튼의 출력 HTML이 무엇입니까? 또는 실제로는 onclick 속성의 값입니다. –

+0

나는 기능의 콘솔 로그를 ddi했고 다음을 얻었다. POST http://127.0.0.1:5000/SaveFile 500 (내부 서버 오류) –

답변

1

나는 이것을 가지고 좋은 시간 동안 놀았지만, onClick에서 몇 가지 따옴표가 필요할 것 같습니다. 예를 들어 제목이 "Soup"인 경우 onClick은 "Soup"값을 전달하지 않고 Soup라는 변수를 찾고있었습니다. 큰 $ (info) .html 문에 이미 큰 따옴표와 큰 따옴표가 모두 있기 때문에 작업하기가 어렵습니다.

var onclickstring = "saveRecipe('" + response[rCnt].title + "','" + response[rCnt].social_rank.toFixed(2) + "','" + response[rCnt].publisher + "','" + response[rCnt].source_url + "')"; 

을 다음과 같이 그 플러그인 : :하지만이 작업에 도착

id="button1" onclick=' + onclickstring + ' title 
관련 문제