Jump to content

AJAX send and recive 1 var


westman

Recommended Posts

hi all,yer i know am a bad programer :facepalm:so what am trying to do is send 1 verible to php and keep the results in a ajax/java veriblehere is what i have so fear..

window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";$.post(url,{ oto_update: oto_update }  ,  function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});chater.value = data;});//if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//}//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);}

i have been testing it but i think thatchater.value = data;});is incorecteany help?

Link to comment
Share on other sites

What is chater a reference to? normally it would be a reference like (1) chater = document.getElementById("whatever_id_ref"); which chater.value = data; will reference to apply value returned OR jquery would use (2)$("#whatever_id_ref").val(data); (1)JS

function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";var chater = document.getElementById("whatever_id_ref");$.post(url,{ oto_update: oto_update }  ,  function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});chater.value = data;}); //if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//} //alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);}

(2)Jquery

function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php"; $.post(url,{ oto_update: oto_update }  ,  function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});//chater.value = data; $("#whatever_id_ref").val(data);}); //if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//} //alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);}

Edited by dsonesuk
Link to comment
Share on other sites

chater is a varible that is empty when the script runs..var chater = "" and in the end i do no want "chater" leaveing the script.am looking to put all the data from oto_work.php in the varible of "chater", and to be used in javascript to run conditions (if, elts and so on..)

Link to comment
Share on other sites

In that case you would not use chater.value, as the '.value' is a reference to a value of a form input such as <input type="text" name="whatever" id="whatever" />, so you would just use chater = data;});

Edited by dsonesuk
Link to comment
Share on other sites

still not seeing my alert boxmy php page looks like this...<?phpecho 'testing123';?>and javascript...

window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";//var chater = "nnnnnn";$.post(url,{ oto_update: oto_update }  ,  function(data) {//alert('got response from server, updating page with ' + data);});//output.innerHTML = data;});//chater.value = data;});chater = data;});//if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//}//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);}

Link to comment
Share on other sites

Sorry the problem is the alert is outside the function it will never show alert there is no alert to trigger from inside the $.post function ON the first ALERT

function otoload() {  var oto_update = <?php echo $id ?>;var url = "../oto_work.php"; $.post(url,{ oto_update: oto_update }  ,  function(data) {chater = data;alert(chater);}); ///alert(chater); otoload_timer = setTimeout("otoload()",10000);}

Edit: got me adding .val() now

Edited by dsonesuk
Link to comment
Share on other sites

thank you so much,with your help i got this fear...

window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";//var chater = "nnnnnn";$.post(url,{ oto_update: oto_update }  ,  function(data) {//alert('got response from server, updating page with ' + data);});//output.innerHTML = data;});//chater.value = data;});chater = data;//alert(chater);//});if (chater == "") {alert("no info");} else {alert("we have info");}});//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);}

so fear so good ;) thank you.

Link to comment
Share on other sites

I think you are looking for

var chater="";window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";$.post(url,{ oto_update: oto_update }  ,  function(data) {chater = data;});if (chater == "") {alert("no info");} else {alert(chater);}otoload_timer = setTimeout("otoload()",10000);}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...