2011-11-04 4 views
0
function somefunction() 
{ 
var xmlhttp; 

if (window.XMLHttpRequest) 
{// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest(); 
} 
else 
{// code for IE6, IE5 
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 

xmlhttp.onreadystatechange=function() 
{ 
if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
alert(xmlhttp.responseText.getElementById('someid').innerHTML); 
} 
} 
xmlhttp.open("GET","1.php",true); 
xmlhttp.send(); 
} 

XMLHTTP의 응답 내가 밖으로 ID가 "someid"id를 사용하여 responsetext에서 요소를 먼저 인쇄하지 않고 가져올 수 있습니까?

alert(xmlhttp.responseText.getElementById('someid').innerHTML); 

있지만 아무튼를 사용하여 시도에서 "100"을 얻을 필요가이

<p id="someid">100</p> 

입니다 일하지 마라.

다른 방법이 있습니까? 사전에

덕분에 당신이 할 수있는 JQuery와의

답변

0

,

$.ajax({ 
type: "GET", 
url: "1.php", 
contentType: "application/json; charset=utf-8", 
dataType: "json", 
success: function(response) { 
    alert($('#SomeID',response.d)); 
    alert($('#SomeID',$('<div/>').html(response.d))); 
}, 
failure: function(msg) { 
    alert(msg); 
} 
관련 문제