Witam,
Dawno nie bawiłem się w pisanie skryptów i wiele wyleciało mi z głowy.
Dlatego też mam prośbę o pomoc
1. Jak dodać zapytanie do URL
2. Jak opóźnić część skryptu
Kawałek z HTML
<script type="text/javascript" language="javascript" src="ajax.js"></script> <div align="center"><h2>*Sprawdź*
</h2> <form action="java script:get(document.getElementById('acctform'));" name="acctform" id="acctform"> <textarea rows="1" cols="1" style="width: 25%; height: 20px" id="search_id"></textarea> <input type="submit" name="button" value="Sprawdź adres" onclick="return Tab_Click(this)"> <div align="center" id="waiting"></div> <div align="center" id="showresults"></div>
Do tego cały ajax.js
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
result = http_request.responseText;
document.getElementById('waiting').innerHTML = '';
document.getElementById('showresults').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}else{
document.getElementById('waiting').innerHTML = '<img src="loading.gif">';}
}
function get(obj) {
var poststr = "" + encodeURI( document.getElementById("search_id").value );
makePOSTRequest('getaddress.php', poststr);
}
No i tu zaczynają się problemy
getaddress.php
// to działa ok
$url = "https://blockchain.info/address/1CoAgA2Bb9XDMsBv6cE1YNuU5Z1BormTTc";
// tu już nie chce zwracać odpowiedzi nawet jak dam
//if (isset ($_POST['search_id'])) {
//$url = "https://blockchain.info/address/{$_POST['search_id']}";
//dalej jest chyba ok bo zwraca dane
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, '$_POST['search_id']');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
$wejscie = curl_exec($ch);
curl_close($ch);
preg_match('/<div class="col-md-5">(.+?)<\/div>/ism', $wejscie, $wyjscie); preg_match('/<div class="col-md-4" style="overflow:visible;">(.+?)<\/div>/ism', $wejscie, $wyjscie1);
// i tu moje drugie pytanie jak opóźnić tą część skryptu
// w ten sposób opóźnia cały skrypt
// wiem że można zrobić to w JS ale nie potrafię tego zrobić a wolał bym aby wszystko było w .php
$baza = "blebleble................";
?>
Z góry dziękuję za wszelką pomoc