2010-12-17 4 views
0

내 링크 (숫자 출력)를 추가하고 합계하는 변수를 반향시키고 있습니다. PHP이기 때문에 먼저로드되고로드가 완료 될 때까지 기다립니다. jQuery로 작성할 수 있습니까? 나는 JavaScript에 아주 익숙하다.자바 스크립트로 변환 된 PHP

<?php 

$a = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.batterytheme&output=number'); 
$a = str_replace(",", "", $a); 
$b = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.connectiontheme&output=number'); 
$b = str_replace(",", "", $b); 
$c = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.icontheme&output=number'); 
$c = str_replace(",", "", $c); 
$d = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.percenttheme&output=number'); 
$d = str_replace(",", "", $d); 
$e = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.statusnotifiertheme&output=number'); 
$e = str_replace(",", "", $e); 
$f = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.cnote&output=number'); 
$f = str_replace(",", "", $f); 
$g = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.iaccescnotekb&output=number'); 
$g = str_replace(",", "", $g); 
$h = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.cnotelite&output=number'); 
$h = str_replace(",", "", $h); 
$i = (301); //From c-note and Multi Lock Screen Theme on Rock Your Phone 
    $j = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.multibrowsericon&output=number'); 
$j = str_replace(",", "", $j); 
$k = file_get_contents('http://modmyi.com/cstats/index.php?package=com.modmyi.changeappstoreiconwithinstallous&output=number'); 
$k = str_replace(",", "", $j); 

$z = $a+$b+$c+$d+$e+$f+$g+$h+$i+$j+$k; 
$z = number_format($z); 
echo $z; 

?> 
+0

이 좀 더 내가 cnotethegr8 @ –

+0

이해 여부를 확실하지 않다 무엇에 확장 할 수 있습니다 : 어떤 TTP : //modmyi.com/cstats/index.php 패키지 = com.modmyi.cnotelite 및 출력 = 수? HTML 자바 스크립트를 반환하고 있습니까? – RageZ

+0

예, AJAX로 동일한 작업을 수행 할 수 있습니다. 그러나 jQuery ajax 도구에 익숙하지는 않으므로이 특성을 다른 사람에게 맡깁니다. –

답변

0

$.ajax을 사용할 수 있습니다. 예를 들면.

var a; 
var b; 
var c; 
$.get('http://modmyi.com/cstats/index.php?package=com.modmyi.batterytheme&output=number', function(data) { 
    a = data; 
}); 

$.get('http://modmyi.com/cstats/index.php?package=com.modmyi.connectiontheme&output=number', function(data) { 
    b = data; 
}); 

... etc 

유일한 까다로운 일은 모든 ajax 호출이 완료되었는지 확인하는 것입니다. 아약스 호출은 비동기식이므로 필요한 모든 데이터가 있는지 확인할 수있는 실제 방법이 없습니다. 하나 쉬운 솔루션 당신은 자바 스크립트를 PHP에 대한 대안 아니라는 것을 먼저 기억해야

$.get('url1', function(data){ 
    $.get('url2', function(data){ 
    }); 
}); 
+1

IMO, ajax 요청을 순차적으로 실행합니다. 첫 번째 요청이 돌아 왔을 때 두 번째 요청을 보내고 계속 반복합니다. 그렇게하면 결과를 추가하는 데 동기화 문제가 발생하지 않습니다. –

+0

감사합니다. RageZ. 그래서 나는이 모든 링크를 통해 계속할 수 있지만 어떻게 출력합니까? 자바 스크립트에 대한 나의 지식은 매우 제한적이다. jQuery를 사용하여 액션과 클래스를 추가했습니다 ... – cnotethegr8

+0

가장 큰 것은 아니지만 여기에 지정된 수의 요청이 완료된 후에 이벤트 발생을 생각해 낸 해결책이 있습니다. http://stackoverflow.com/questions/4368946/javascript-callback-for-multiple-ajax -calls/4369592 # 4369592 – subhaze

0

즉, 앞의 아약스 호출의 성공 함수 콜백에서 한 번 더 아약스 전화를 걸 것이다. PHP는 서버 측 언어이고 JavaScript는 클라이언트 측 언어입니다. 하나는 다른 하나를 대체 할 수 없습니다.

해당 샘플을 사용 가능한 JS로 변환 할 수 있습니다. 하지만 서버 측 구현과 다른 점은 사용자 에이전트와 JavaScript를 실행할 수있는 기능에 완전히 의존한다는 것입니다.

XML 형식의 광고를 반환하는 새로운 PHP 스크립트를 만들고 XMLHttpRequest 객체를 사용하여 JavaScript를 통해 광고를 얻을 수 있습니다. 원한다면 초 단위로 샘플을 쓸 수 있습니다.

+0

나는 그것을 원합니다. 고맙습니다! – cnotethegr8

0

$ 아약스 ({URL '& http://modmyi.com/cstats/index.php?package=com.modmyi.batterytheme 출력 = 번호'성공 : 기능 (데이터) {$ ('.result') .html (data);}});

나은 배열의 결과를 저장하거나

$ 대체하여 여기 자체 그것을 다른 변수를 추가하는 HTML (데이터) ('결과..');

+0

다른 URL을 순차적으로 추가하면 처리가 완료됩니다. 데이터를 출력하려면 $ ('# result')와 같은 것이 있습니다 .html (data); 여기서 id = "result"인 div/span은 물건을 표시하려는 위치이며 데이터는 총합입니다. – Joe

관련 문제