473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to build ajax function?

Hello,

I am trying to update data on my webpage using AJAX. The idea is when a user clicks a checkbox the data will be updated.

This is the code that I have so far:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var refreshData = function() {
  3. asdf
  4. };
  5. $('input[type=checkbox]').live( 'click', refreshData );
  6. </script>
  7.   <input type="checkbox" id="checkbox_<?= $statistic_id; ?>" <?= $i==0 ? 'checked="checked"' : null; ?> onclick="refreshData()" />
  8.  
I am having trouble building the refreshData function because I am very unfamiliar with AJAX. The AJAX function would primarily consist of building the ajax query and then executing the ajax query and then taking the returned data and displaying it

For your reference, I am pulling data from this source: http://tyrone.pae.me/pulldata.php?p=1&s=40 where p is a player id number and s is a statistic associated with the player. You'll notice that I reference a statistic_id in the id of the checkbox. Not sure if that is helpful or not.

If you have any ideas on how this can be achieved or need more information, please reply to this thread. Thanks!
Oct 16 '10 #1
4 1582
gits
5,390 Expert Mod 4TB
so basically your question is: how to use the jQuery ajax methods in your case?
Oct 17 '10 #2
Yes, I'm just unsure as to which ones are most pertinent in my situation. Could you advise further on which methods you would recommend for my situation?
Oct 18 '10 #3
gits
5,390 Expert Mod 4TB
??? ... what is your situation? basically to retrieve the data seems quite simple with jQuery ... and then you would just need to have your response-handling-callback to update the corresponding nodes.

if you use such a json structure as you did in your example-link then you would need to eval it and just process the JavaScript structure. you could even prepare that more by creating html-fragments serverside that would replace some current nodes in your document ... which could avoid expensive DOM manipulation with JavaScript etc. ...

@the moment i think that i just don't get the real point of your question?
Oct 19 '10 #4
Okay, to update you on where I am currently, I have written the following code:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.          var drawLineOnGraph = function ( array ) {
  3.  
  4.             line = new RGraph.Line('myLine', array );
  5.             line.Draw();
  6.  
  7. }
  8.  
  9.    function refreshData() {
  10.    var url = "/pulldata.php?p=" + pid + "&s=" + statistic_id + "";
  11.    $.getJSON( url,
  12.    function(data){
  13.      for ( pid in data ) {
  14.        for ( statistic_id in data[ pid ] ) {
  15.          console.log( data[ pid ][ statistic_id ] );
  16.          drawLineOnGraph( data[pid][statistic_id] );
  17.       }
  18.     }
  19.    } );
  20. </script>
  21.  
This is the part of my code where I am trying to pull data using AJAX and then I write the values on a graph that I am building. A secondary component of the process is that the redrawing of the line is initiated by selecting a check box. Here is the code I have for the checkbox:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. $('input[type=checkbox]').live( 'click', refreshData );
  3. </script>
  4. <div id="playerstats">
  5. <table width="265px" border="0" >
  6. <? $i = 0; foreach ($combine as $statistic_id => $stat_values): ?>
  7. <tr>
  8. <td NOWRAP style="vertical-align:middle; font-size : 11px;">
  9.   <input type="checkbox"  id="checkbox_<?= $statistic_id; ?>" <?= $i==0 ? 'checked="checked"' : null; ?> />
  10.   <label for="checkbox_<?= $statistic_id; ?>"><?= getStatisticFromId ( $statistic_id ); ?></label>
  11. </td>
  12. </tr>
  13. <? $i++; endforeach; ?>
  14. </table>
  15. </div>
  16.  
The idea is to redraw the line on my graph (I am using RGraphs) when a checkbox is selected. I hope that clarifies a little better.
Oct 19 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon | last post by:
Is it possible in VB to dynamically build a function call? eg Something like: strParams = strParam(0) & ", " & strParam(1) strFunc = "Logon" if not( frmMain.objMxAPI.strFunc( strParams )) ...
5
by: jamo | last post by:
Hi all, can anyone help with this problem. I want to call an Ajax function from a list menu *onchange*, my javascript is not good. Code below: Menu: <select name="menu1"...
3
by: Sandman | last post by:
So, I've used ajax for quite some time for different stuff. Mostly I just feed a funktion I made with the ID of the DIV that should be updated with the output from page XXX.php Now I want to...
1
by: c19h28o2 | last post by:
Hi, I'm a little stuck with Ajax (really am not getting it at the moment!) I'm trying to write into a div when something is typed into a box... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML...
1
by: shivendravikramsingh | last post by:
hello friends, actually i have a problem in using conditional statement in ajax function i m tring to describe my problem properly,what i want when i select a value form a combo its vlue is passed...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
3
by: jack21 | last post by:
I have a main window containing a list of items along with some buttons. If the user clicks the 'View' button, I open a child window containing the details of the item along with 'Approve' and...
12
by: robin1983 | last post by:
hi everyone, i m very new to Ajax, and this is my first program in Ajax. I dont know what is wrong in the script. Please help me to find out the error, The main error is the value that i suppose to...
17
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
2
by: panos100m | last post by:
Hi on page load a javascript functions (timedCount()) is executed (timer) which executes another javascript function (ajax function:findprov(divtowrite) ) in turn this calls a php file to query a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.