2016-07-18 3 views
4

어쩌면 이상한 제목입니다하지만 내가 원하는 모든 그렇게하는 것입니다 그것을로드를 열지 않고 외부 링크를 액세서하기 url 어떻게 단지

192.168.1.2?light=1

등을 통하여 - 빛

192.168.1.2?light=0은 -

,691을 불

괜찮 았지만 문제는 웹 사이트 (단추 또는 정상적인 링크에서)에서 해당 링크를 브라우저에 열면 , js 또는 jquery을 사용하여로드하는 것이 가능하다는 것입니다. 또는 단순히 html을 사용하고 계신가요? 다음 웹 페이지에서이 링크를 사용하려면

+0

'컬'했습니까? –

+0

아니요, 저는 ... –

+0

'컬 (curl)'은 과도한 상황입니다. 정말로 필요한 것은 AJAX 호출이며 링크의 클릭 이벤트에 첨부됩니다. – Anton

답변

3

당신이 jQuery로 웹 페이지를 가지고 가정.

HTML

<a class="access-only" href="http://192.168.1.2?light=1">Turn on the light</a> 
<a class="access-only" href="http://192.168.1.2?light=0">Turn off the light</a> 

JS

$(document).ready(function() { 
    // Attach click handler to all "access-only" links. 
    $('a.access-only').click(function() { 
     // Once the link is clicked, access its URL with a GET request. 
     $.get($(this).attr('href'), function(response) { 
      // Do nothing here, the URL has been accessed. 
     }); 

     // Return false to prevent the browser's default click action. 
     return false; 
    }); 
}); 
+0

감사합니다 안톤, 나는 다른 사람을위한 가장 완벽한 감사이기 때문에 당신의 대답을 선택합니다, 그것은 단지 잘 작동합니다! :) –

+0

@MarcelDomuta, 오신 것을 환영합니다 :) – Anton

0

(jQuery를 필요) :

$.get('http://192.168.1.2?light=1', function(response) { 
    console.log(response); 
}); 
0

이 작업을 시도 할 수 있습니다.

$(".yourAtag").click(function(e){ 
    e.preventDefault(); 
    $.ajax({url: this.href, success: function(result){ 
     alert('success!'); 
    }}); 
});