4

Loading the variable of php in javascript continuously

 3 years ago
source link: https://www.codesd.com/item/loading-the-variable-of-php-in-javascript-continuously.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Loading the variable of php in javascript continuously

advertisements

I am currently trying to draw some dynamically loaded graphs using google's visualization tools.

I want to pull the data from an sql database. I have a php script (getnumber.php) that is capable of doing so.

I am trying to use this php script within my javascript that draws the graphs.

<html>
<head>
<!--Load the AJAX API-->
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript">
  function drawChart(Z)
  {
    tmpdata = new google.visualization.DataTable();
    datalist.push(tmpdata);
    datalist[Z].addColumn('string', 'Complete');
    datalist[Z].addRows([['Finished', $.ajax({url:"getnumber.php"})], ['Incomplete', 10]]);
    .
    .
    .
  }
  window.setInterval("drawChart()", 1000);
</script>

I realise that this use of $.ajax is completely wrong but I'm stumped!


You should try using either $.post() or $.get() functions instead of using the basic ajax one. Anyways, you can manipulate the data in thsoe 3 functions this way

$.post('getnumber.php',function(data){
/* Do whatever you want with the data you grabbed from the php page. */
});

I'm not sure of what your question is exactly, but I hope this will help you.

Have a nice day!

EDIT: The functions themselves don't contain the data, it is contained into the function(data){} portion of the $.ajax() call.

Edit2: The $.ajax(); function has a parameter called success(data, textStatus, jqXHR)which can be used, compared to the two other functions.

http://api.jquery.com/jQuery.ajax/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK