Well, you get to smash the stack due to name being placed after input :P
The order of the variables isn't the main problem. The main problem is that he's writing name (which could be up to 75 characters long) into an array which is only 50 characters long. Either increase the size of name, or use sscanf(input, "%50s %u", name, &age).
You should be checking if the return from sscanf() is equal to the number of fields parsed. I.e. sscanf("%50s %u", name, &age) == 2.
I also like to add an extra space around my format string so it will gobble leading and trailing whitespace:
sscanf(input, " %50s %u ", name, &age) == 2.
Finally, this will still match inputs with extra garbage at the end. You can fail if there's extra garbage by comparing the length of the matched string with the length of the entire string: sscanf(input, " %50s %u %n", name, &age, &len) == 2 && len == strlen(input)
Well, if it appeared before then it would just overwrite the start of the input string, which is still bad, but not quite as bad.
So uh, let's say I have this $2000 server doing absolutely nothing. Let's also say I have git repo on a server. Is there anyway to using this server to make builds based off that git repo whenever there's a change? I'd need a windows and linux executable, if that helps, so I'm assuming cmake of some sort.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
I have a semi-interesting database design question.
I'm working on creating a WebDAV emulator with Django.
Django will store information on files and folders in SQL (actual file data stored on a filesystem, not in SQL itself) and handle WebDAV protocol requests.
The area where I am getting fuzzy in this design is how to handle folders. There's no folder programming interface, so everything is represented by strings. I feel like I do in fact need an actual Folder object in Django because I have to serve information on specific folders al a carte. So the issue comes with storing the file and folder path information.
I'm basing my work off of a WebDAV emulator written for Google App Engines where every file and folder entity in SQL is stored with a full path (therefore if a file has two parent folders, the file path field is written '/parent1/parent2/file.png'). I'm not crazy about this because I then have to babysit the value of the path field during move operations. Moving a folder with 1000 files means I need to do 1000 row updates to update the path value.
On the flipside, I could just store the normalized path representation of the single entity (a.k.a. the file or folder name) and reconstruct full paths recursively during runtime. This also could potentially suck because if I have a file with 10 parents then that seems to me like one hell of a query because I would need all 10 parent path fields to reconstruct the path.
My brain is telling me that the second option is ultimately better. I can probably figure out how to make that kind of query at least tolerable. I'm not so crazy about having to deal with an unknown number of row updates per move. That is so exploitable.
Short of that, I am looking for other ideas on how to implement a WebDAV service that interfaces with the authentication module of a proper HTTP web framework. A big reason I need these entities in a database is for complex authentication. Folder level authentication and file level permissions to multiple users and the like.
WebDAV isn't exactly as pervasive as Rails so there's not much written on this subject, so I'm cobbling together my knowledge from a very few people who've taken the subject to open source.
*edit*
This for example might be far less egregious than trying to mock a WebDAV filesystem with SQL and Django
Well, you get to smash the stack due to name being placed after input :P
The order of the variables isn't the main problem. The main problem is that he's writing name (which could be up to 75 characters long) into an array which is only 50 characters long. Either increase the size of name, or use sscanf(input, "%50s %u", name, &age).
You should be checking if the return from sscanf() is equal to the number of fields parsed. I.e. sscanf("%50s %u", name, &age) == 2.
I also like to add an extra space around my format string so it will gobble leading and trailing whitespace:
sscanf(input, " %50s %u ", name, &age) == 2.
Finally, this will still match inputs with extra garbage at the end. You can fail if there's extra garbage by comparing the length of the matched string with the length of the entire string: sscanf(input, " %50s %u %n", name, &age, &len) == 2 && len == strlen(input)
Yeah, when I did C in college it was all fgets, all the time. I don't think we even used scanf(), but as my original response indicated, we weren't big on this interactivity stuff. (I mean, after all, if you want to write user interfaces that's what HCI is for, isn't it? ;-) )
I really, really hate people who write code that is critical to our system and then don't put it in version control. This is really making my current work setting up our platform on new servers so that we can sell off the old servers a total nightmare. All the important stuff seems to work now, but there's lots of stupid little crap.
So uh, let's say I have this $2000 server doing absolutely nothing. Let's also say I have git repo on a server. Is there anyway to using this server to make builds based off that git repo whenever there's a change? I'd need a windows and linux executable, if that helps, so I'm assuming cmake of some sort.
Why yes you can do it with [email protected]. The other option is to write a shell script that checks every X minutes for new updates, which was how we did/do things before [email protected]
Edit:
If you are interested in the shells scripts we use, I can show you where to look. But most of them are fairly project/os specific.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
DVGNo. 1 Honor StudentNether Institute, Evil AcademyRegistered Userregular
edited February 2011
So I'm making a simple iOS game (nothing graphical, using normal UI controls).
I've got a Core Data database with models of Characters and Monsters, which have game statistics tied to them.
When an encounter is created, the encounter just holds a relationship to the individual Characters in the persistent store that are selected for that encounter. However, for the monsters, I want to be able to have several copies of a generic monster for the characters to fight. (5 Orcs, for example).
Because of this, i can't just have a relationship handle it like I can for characters, because if I, deal damage, for instance, to a monster, all 5 orcs will take the damage, and that's not what we're looking for.
So how do I handle managing multiple copies of a baseline monster and still be able to interact with them individually? I feel like this is one of those things where i know the answer but i just can't think of it for some reason.
your monster entity should contain your encounter foreign key, not the other way around.
*edit*
also core data sucks
Jasconius on
0
DVGNo. 1 Honor StudentNether Institute, Evil AcademyRegistered Userregular
edited February 2011
Okay, I think I figured it out actually.
I can make another model (Called EncounterStats in my mind) which holds a relationship to a Monster or Character, and their non-static statistics like currentHP, and refers to the baseline character for static stats like maximumHP.
That would certainly work but that sounds like a roundabout way of achieving it.
You might want to provide to visualization for how you're hauling all your data around.
Jasconius on
0
DVGNo. 1 Honor StudentNether Institute, Evil AcademyRegistered Userregular
edited February 2011
Right now it's 3 View Controllers. Characters, Monsters and Encounters. Characters and Encounters is the only thing that does anything now, and I'm using temporary quick-and-dirty view controllers to add data into those lists.
I was thinking ahead this morning about monsters, and how there will be several generic monsters in a given encounter.
So now I've evolved to this:
Character
name:string
maximumHP:int32
has_one type
has_many encounters
Type
name //eg "Monster" or "Character"
belongs_to character
CharacterStatus
currentHP:int32
has_one character
belongs_to encounter
Encounter
name:string //e.g. "Bar Fight"
has_many characterStatus
That's more or less a rough draft. The whole goal is to be able to get a a UITableView that looks like
Am I correct in assessing that your actual monster templates are stored in Core Data?
If that is correct then I would say that's probably your biggest problem. That's the kind of stuff you'd configure in the initialization cycle of an object.
Jasconius on
0
DVGNo. 1 Honor StudentNether Institute, Evil AcademyRegistered Userregular
Am I correct in assessing that your actual monster templates are stored in Core Data?
If that is correct then I would say that's probably your biggest problem. That's the kind of stuff you'd configure in the initialization cycle of an object.
Well, everything in this case is a user-created object. The user inputs the player characters and monsters, which are stored in Core Data.
The user creates player characters and monsters, then creates an encounter, and selects the player characters participating and the monsters participating, then uses some controls to interact with those objects.
My problem is I'm trying to profile a program which launches a Java process. I don't want to profile the child process, just the parent. However, whenever I run my program in Quantify, it attempts to start profiling the Java process, reports that Quantify does not support Java, and kills the child. Everything I've found on the Internet is a few years old and indicates that by default quantify does not instrument child processes. Any idea on how I can stop Quantify from committing Java infanticide?
Right now it's 3 View Controllers. Characters, Monsters and Encounters. Characters and Encounters is the only thing that does anything now, and I'm using temporary quick-and-dirty view controllers to add data into those lists.
I was thinking ahead this morning about monsters, and how there will be several generic monsters in a given encounter.
So now I've evolved to this:
Character
name:string
maximumHP:int32
has_one type
has_many encounters
Type
name //eg "Monster" or "Character"
belongs_to character
CharacterStatus
currentHP:int32
has_one character
belongs_to encounter
Encounter
name:string //e.g. "Bar Fight"
has_many characterStatus
That's more or less a rough draft. The whole goal is to be able to get a a UITableView that looks like
While only having "Orc" be a single row in the database.
I dunno mang.
I will make the disclaimer than I am a vehement opponent of Core Data usage for most things, but it honestly sounds like you're kind of trying to make Core Data program for you, instead of programming for Core Data.
So, without telling you to blow up your entire app..
"Monsters" and "Monster Templates" need to be separate database entities. A "Monster" should take "Monster Template" in its constructor.
This way you don't have to worry about weird ass quirks like hitting one monster and it impacting everything because they're all actually the same Core Data row.
Sorry to interrupt your discussion. I've actually never even been in this forum before, aside from asking about a phone I was considering buying a little while back.
I'm a programmer/web developer by trade working in a small part of a big company and it has recently occurred to me that its shameful that I don't have my own website. If/when I ever want to change jobs I'll need something to show off my abilities. This mostly comes from interviewing a ton of candidates for a job and being miserably disappointed with both their skills and their examples.
So does anyone know a good .Net capable web host? I've never even considered any of this before and I'd love to trust someone's opinion instead of the purchased adspace on google.
You don't *need* your own website. Plenty of good programmers, namely ones with shit to do, don't have websites, and still get jobs. I've never had one.
As far as .NET... none that are cheap. .NET shared hosting usually comes in two varieties: cheap and shitty, or expensive and pretty decent.
You don't *need* your own website. Plenty of good programmers, namely ones with shit to do, don't have websites, and still get jobs. I've never had one.
As far as .NET... none that are cheap. .NET shared hosting usually comes in two varieties: cheap and shitty, or expensive and pretty decent.
You get what you pay for I suppose...
In the short term shitty is probably going to do just fine. All I need is a DB and some bandwidth, it will mostly be for me to play around in.
Yeah I understand its not a strict requirement, I'm just tired of wasting my time on video games and TV when I could be playing around more. There's a ton of things that I get the impulse to try out at work but can't justify putting into a corporate site (even an internal one). I'm a big fan of javascript widgets, for one thing, and I've encountered plenty of gaps in easily available open source ones so I may as well contribute a few to the ether.
Edit: Oh, I forgot to ask, a friend pointed me to https://www.discountasp.net/ saying his company uses it. Seems pretty cheap, anyone used it before?
When I say shitty, I mean configuration nightmares, not necessarily performance shitty.
As a .NET programmer I imagine you are aware of .NET's absolutely ridiculous configuration environment and how stupid IIS6 is (a lot of cheap hosts still use IIS6 when last I checked)
I used three or four .NET hosts back when I did .NET and each one of them had their own unique nonsense to slice through.
The best one I ever used was Mosso (now Rackspace Cloud) but I believe their service is something like $texas per month. But at least there you could file support tickets to get account specific IIS configuration done.
If you use something on par with Godaddy or 1and1, you get what you get.
If your primary objective is only to create a website to showcase your work, then there are ways of doing that that don't entail literally hosting and running your portfolio code for people to see. Employers will care more about seeing technique in source code than seeing "oh yeah, that DataGrid totally pages".
Given that, there are about 1000000000 easier ways to host some sort of informational website/blog than using .NET
Sparser, I'd just skip looking for an ASP host. Check out a nice LAMP hosting package. There are lots of inexpensive ones out there with good support. I'd personally recommend Dreamhost. They're who I'm with and I've been happy with them.
[ed] Ok, so one thing about them that I was really happy about (which may be an over-reaction, but I've not had another host offer it) was subdomain redirection/forwarding. So I'm able to take my domain and point private.mydomain.com to my home IP; which I just think is the bee's knees.
Wel, uh, Sparser, if you do sign up it looks like it'd be awesome if you shoved in my email address as someone that referred you during the sign-up process. grkaiser [at] gmail [period] com
[ed] Actually, it looks like I can generate custom promo codes too, with things like a free domain registration for you or a free unique IP for you, if either of those would make Dreamhost more interesting.
I'm a whooooooooooooooore and it's all Allistair's fault for pointing out that there is a referral system.
iTunesIsEvil on
0
DVGNo. 1 Honor StudentNether Institute, Evil AcademyRegistered Userregular
I will make the disclaimer than I am a vehement opponent of Core Data usage for most things, but it honestly sounds like you're kind of trying to make Core Data program for you, instead of programming for Core Data.
So, without telling you to blow up your entire app..
"Monsters" and "Monster Templates" need to be separate database entities. A "Monster" should take "Monster Template" in its constructor.
This way you don't have to worry about weird ass quirks like hitting one monster and it impacting everything because they're all actually the same Core Data row.
To be fair, I'm just doing this as a learning project. I see what your saying though, store the monster base stats as a monster template in the DB then insert the monster rows based on those templates when the encounter is created. That makes sense, thanks.
Anyone have any experience interfacing to one of those? I want to capture patient names from a swiped card (credit/debit) to help expedite check in and show account information. Maybe even do bill pay at the check in terminal if they want. I assume it will give first/last name and the card number/cv2 code the last two don't really matter to me until I do bill pay but the first/last would help people check in and out way faster. Am I assuming correctly?
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
I personally use WebFaction. They support a bunch of different languages and static layouts, and also allow full SSH access to your machine, all the while charging like a virtual private server host. They're great.
Anyone know why I wouldn't be able to call a javascript function from the onclick event in an <a> tag?
I'm using jQuery to navigate a page using javascript. In index.php, I have an AJAX request that loads the content of <div id="gameList">. That content has links in it which should load new content into the same div.
That content has links which call a function defined in a .js file which is included at the top of index.php. Unfortunately, the function is never called, though if I change it to alert() the dialog box is launched correctly.
Oh god damn it, I'm dumb. I didn't pass the handler correctly through AJAX, so to simplify testing I reduced the function to document.alert() which isn't actually a function! Changing it to just alert() and moving my $("#voteLink").click() statement fixed up everything.
Well, now that I've recovered from my brief stupidity I have a best practices question.
If I have a variable in a PHP file (e.g. $id), and I'm printing it to HTML as part of an AJAX request, what's the best way to package it into a link which will generate a new AJAX request?
The path goes something like index.php -> AJAX fills div with links from display.php and adds a new AJAX call to their click events -> clicking links executes the AJAX call to vote.php, but vote.php needs the $id from display.php.
I thought of using the id field in display.php to do something like <a id="game-<?php echo $id; ?>">, and then extract the ID from the string, but that seems kind of hacky. Any recommendations?
You should consider script/JSON, since then you can do things right and separate your presentation from your logic/data. Your AJAX request should handle the data, your client-side JS and HTML should handle the presentation.
You should consider script/JSON, since then you can do things right and separate your presentation from your logic/data. Your AJAX request should handle the data, your client-side JS and HTML should handle the presentation.
You're asking for best practices after all. :^:
If you need an example then just ask.
I'm at my day job, and I have a hard time visualizing the code when I'm screaming inside. Do you have a link or anything I could look at?
Edit:
The bolded is exactly the kind of thing I'm trying to get at.
...
// call this with a link or onclick or what have you
function openVotePane(id)
{
$.ajax({
dataType: 'json',
data: {
call: 'votePane',
id: id,
},
success: loadVotePane
});
}
function loadVotePane(o)
{
// generate HTML here for presenting the vote interface based on the data in o
}
...
controller.php
$call = $_POST['call'];
...
if ($call == 'votePane')
{
$o = array();
// fill $o with relevant data
print json_encode($o);
}
...
Obviously that is just to illustrate where to break things up, code it much better than that. ;-) You can get a MVC type setup, keeping things organized has been really vital to me since I am working on an AJAX web game with simultaneous users interacting and allowing the same account to be open in multiple browsers at once.
edit: to be clear, the View is the HTML-generating PHP and the JavaScript, the Controller is my back-end PHP logic, and the Model is of course my class-based data model that allows my Controller to interface with the database in a consistent fashion.
Posts
Well, if it appeared before then it would just overwrite the start of the input string, which is still bad, but not quite as bad.
I'm working on creating a WebDAV emulator with Django.
Django will store information on files and folders in SQL (actual file data stored on a filesystem, not in SQL itself) and handle WebDAV protocol requests.
The area where I am getting fuzzy in this design is how to handle folders. There's no folder programming interface, so everything is represented by strings. I feel like I do in fact need an actual Folder object in Django because I have to serve information on specific folders al a carte. So the issue comes with storing the file and folder path information.
I'm basing my work off of a WebDAV emulator written for Google App Engines where every file and folder entity in SQL is stored with a full path (therefore if a file has two parent folders, the file path field is written '/parent1/parent2/file.png'). I'm not crazy about this because I then have to babysit the value of the path field during move operations. Moving a folder with 1000 files means I need to do 1000 row updates to update the path value.
On the flipside, I could just store the normalized path representation of the single entity (a.k.a. the file or folder name) and reconstruct full paths recursively during runtime. This also could potentially suck because if I have a file with 10 parents then that seems to me like one hell of a query because I would need all 10 parent path fields to reconstruct the path.
My brain is telling me that the second option is ultimately better. I can probably figure out how to make that kind of query at least tolerable. I'm not so crazy about having to deal with an unknown number of row updates per move. That is so exploitable.
Short of that, I am looking for other ideas on how to implement a WebDAV service that interfaces with the authentication module of a proper HTTP web framework. A big reason I need these entities in a database is for complex authentication. Folder level authentication and file level permissions to multiple users and the like.
WebDAV isn't exactly as pervasive as Rails so there's not much written on this subject, so I'm cobbling together my knowledge from a very few people who've taken the subject to open source.
*edit*
This for example might be far less egregious than trying to mock a WebDAV filesystem with SQL and Django
http://stackoverflow.com/questions/700480/control-access-to-webdav-apache-using-python
Although this doesn't really account for the type of folder-specific authentication that I need.
Yeah, when I did C in college it was all fgets, all the time. I don't think we even used scanf(), but as my original response indicated, we weren't big on this interactivity stuff. (I mean, after all, if you want to write user interfaces that's what HCI is for, isn't it? ;-) )
SE++ Forum Battle Archive
Why yes you can do it with [email protected]. The other option is to write a shell script that checks every X minutes for new updates, which was how we did/do things before [email protected]
Edit:
If you are interested in the shells scripts we use, I can show you where to look. But most of them are fairly project/os specific.
I've got a Core Data database with models of Characters and Monsters, which have game statistics tied to them.
When an encounter is created, the encounter just holds a relationship to the individual Characters in the persistent store that are selected for that encounter. However, for the monsters, I want to be able to have several copies of a generic monster for the characters to fight. (5 Orcs, for example).
Because of this, i can't just have a relationship handle it like I can for characters, because if I, deal damage, for instance, to a monster, all 5 orcs will take the damage, and that's not what we're looking for.
So how do I handle managing multiple copies of a baseline monster and still be able to interact with them individually? I feel like this is one of those things where i know the answer but i just can't think of it for some reason.
*edit*
also core data sucks
I can make another model (Called EncounterStats in my mind) which holds a relationship to a Monster or Character, and their non-static statistics like currentHP, and refers to the baseline character for static stats like maximumHP.
You might want to provide to visualization for how you're hauling all your data around.
I was thinking ahead this morning about monsters, and how there will be several generic monsters in a given encounter.
So now I've evolved to this:
That's more or less a rough draft. The whole goal is to be able to get a a UITableView that looks like
While only having "Orc" be a single row in the database.
If that is correct then I would say that's probably your biggest problem. That's the kind of stuff you'd configure in the initialization cycle of an object.
Well, everything in this case is a user-created object. The user inputs the player characters and monsters, which are stored in Core Data.
The user creates player characters and monsters, then creates an encounter, and selects the player characters participating and the monsters participating, then uses some controls to interact with those objects.
Once again thanks to all who upvoted me.
My problem is I'm trying to profile a program which launches a Java process. I don't want to profile the child process, just the parent. However, whenever I run my program in Quantify, it attempts to start profiling the Java process, reports that Quantify does not support Java, and kills the child. Everything I've found on the Internet is a few years old and indicates that by default quantify does not instrument child processes. Any idea on how I can stop Quantify from committing Java infanticide?
All in Windows, by the way.
I dunno mang.
I will make the disclaimer than I am a vehement opponent of Core Data usage for most things, but it honestly sounds like you're kind of trying to make Core Data program for you, instead of programming for Core Data.
So, without telling you to blow up your entire app..
"Monsters" and "Monster Templates" need to be separate database entities. A "Monster" should take "Monster Template" in its constructor.
This way you don't have to worry about weird ass quirks like hitting one monster and it impacting everything because they're all actually the same Core Data row.
I'm a programmer/web developer by trade working in a small part of a big company and it has recently occurred to me that its shameful that I don't have my own website. If/when I ever want to change jobs I'll need something to show off my abilities. This mostly comes from interviewing a ton of candidates for a job and being miserably disappointed with both their skills and their examples.
So does anyone know a good .Net capable web host? I've never even considered any of this before and I'd love to trust someone's opinion instead of the purchased adspace on google.
As far as .NET... none that are cheap. .NET shared hosting usually comes in two varieties: cheap and shitty, or expensive and pretty decent.
You get what you pay for I suppose...
In the short term shitty is probably going to do just fine. All I need is a DB and some bandwidth, it will mostly be for me to play around in.
Yeah I understand its not a strict requirement, I'm just tired of wasting my time on video games and TV when I could be playing around more. There's a ton of things that I get the impulse to try out at work but can't justify putting into a corporate site (even an internal one). I'm a big fan of javascript widgets, for one thing, and I've encountered plenty of gaps in easily available open source ones so I may as well contribute a few to the ether.
Edit: Oh, I forgot to ask, a friend pointed me to https://www.discountasp.net/ saying his company uses it. Seems pretty cheap, anyone used it before?
As a .NET programmer I imagine you are aware of .NET's absolutely ridiculous configuration environment and how stupid IIS6 is (a lot of cheap hosts still use IIS6 when last I checked)
I used three or four .NET hosts back when I did .NET and each one of them had their own unique nonsense to slice through.
The best one I ever used was Mosso (now Rackspace Cloud) but I believe their service is something like $texas per month. But at least there you could file support tickets to get account specific IIS configuration done.
If you use something on par with Godaddy or 1and1, you get what you get.
If your primary objective is only to create a website to showcase your work, then there are ways of doing that that don't entail literally hosting and running your portfolio code for people to see. Employers will care more about seeing technique in source code than seeing "oh yeah, that DataGrid totally pages".
Given that, there are about 1000000000 easier ways to host some sort of informational website/blog than using .NET
Anyways, thanks for the advice, I will keep looking around.
...
I started going into what all they let you have on their base hosting plan (which I feel like is great) but I re-read it and I sound like a shill. So, check 'em out if you want, I think they're a good deal.
[ed] Ok, so one thing about them that I was really happy about (which may be an over-reaction, but I've not had another host offer it) was subdomain redirection/forwarding. So I'm able to take my domain and point private.mydomain.com to my home IP; which I just think is the bee's knees.
I am impressed at your self-restraint in not putting in refferal links there iTunesIsEvil.
I made a game, it has penguins in it. It's pay what you like on Gumroad.
Currently Ebaying Nothing at all but I might do in the future.
>.>
Wel, uh, Sparser, if you do sign up it looks like it'd be awesome if you shoved in my email address as someone that referred you during the sign-up process. grkaiser [at] gmail [period] com
[ed] Actually, it looks like I can generate custom promo codes too, with things like a free domain registration for you or a free unique IP for you, if either of those would make Dreamhost more interesting.
I'm a whooooooooooooooore and it's all Allistair's fault for pointing out that there is a referral system.
To be fair, I'm just doing this as a learning project. I see what your saying though, store the monster base stats as a monster template in the DB then insert the monster rows based on those templates when the encounter is created. That makes sense, thanks.
There are some gems in there.
Anyone have any experience interfacing to one of those? I want to capture patient names from a swiped card (credit/debit) to help expedite check in and show account information. Maybe even do bill pay at the check in terminal if they want. I assume it will give first/last name and the card number/cv2 code the last two don't really matter to me until I do bill pay but the first/last would help people check in and out way faster. Am I assuming correctly?
I'm using jQuery to navigate a page using javascript. In index.php, I have an AJAX request that loads the content of <div id="gameList">. That content has links in it which should load new content into the same div.
That content has links which call a function defined in a .js file which is included at the top of index.php. Unfortunately, the function is never called, though if I change it to alert() the dialog box is launched correctly.
index.php
gameregistrydisplay.php
gameregistrycontroller.js
function VoteClick() { document.alert("vote!"); } ... function OnReady() { $.ajax({ method: "get", url: "gameregistrydisplay.php", beforeSend: ShowLoadingMessage, error: ShowErrorMessage, success: DisplayContent }); } $(document).ready( OnReady );Edit:
Oh god damn it, I'm dumb. I didn't pass the handler correctly through AJAX, so to simplify testing I reduced the function to document.alert() which isn't actually a function! Changing it to just alert() and moving my $("#voteLink").click() statement fixed up everything.
If I have a variable in a PHP file (e.g. $id), and I'm printing it to HTML as part of an AJAX request, what's the best way to package it into a link which will generate a new AJAX request?
The path goes something like index.php -> AJAX fills div with links from display.php and adds a new AJAX call to their click events -> clicking links executes the AJAX call to vote.php, but vote.php needs the $id from display.php.
I thought of using the id field in display.php to do something like <a id="game-<?php echo $id; ?>">, and then extract the ID from the string, but that seems kind of hacky. Any recommendations?
<a id="game-<?php=$id;?>">
I don't think that works unless short tags are turned on, though, changing it to <?=$id;?>
You should consider script/JSON, since then you can do things right and separate your presentation from your logic/data. Your AJAX request should handle the data, your client-side JS and HTML should handle the presentation.
You're asking for best practices after all. :^:
If you need an example then just ask.
I'm at my day job, and I have a hard time visualizing the code when I'm screaming inside. Do you have a link or anything I could look at?
Edit:
The bolded is exactly the kind of thing I'm trying to get at.
I leave it to you to format and do these tags properly!
page.php
script.js
... // call this with a link or onclick or what have you function openVotePane(id) { $.ajax({ dataType: 'json', data: { call: 'votePane', id: id, }, success: loadVotePane }); } function loadVotePane(o) { // generate HTML here for presenting the vote interface based on the data in o } ...controller.php
$call = $_POST['call']; ... if ($call == 'votePane') { $o = array(); // fill $o with relevant data print json_encode($o); } ...Obviously that is just to illustrate where to break things up, code it much better than that. ;-) You can get a MVC type setup, keeping things organized has been really vital to me since I am working on an AJAX web game with simultaneous users interacting and allowing the same account to be open in multiple browsers at once.
edit: to be clear, the View is the HTML-generating PHP and the JavaScript, the Controller is my back-end PHP logic, and the Model is of course my class-based data model that allows my Controller to interface with the database in a consistent fashion.