-2

I want to have modal windows produced by Javascript for a calendar program, acting sort of like tooltips (wave your mouse pointer over an event link, and you get a modal popup describing the event). The events are stored in MySQL, accessed by PHP.

From what I'm reading, I can get that information into my Javascript modal popup two ways:

  • An Ajax call: write a PHP script to generate that information, and use Ajax to call it, when I open the modal window

  • Let PHP generate a hidden modal window for every link in the calendar; Javascript can activate the appropriate one when opening the modal window.

Will either of these not work, or does either seem like horrible programming style? I'm preparing for a class (teaching it, not taking it), so I want things to be as simple and easy to read as possible. To whatever degree possible, I'm using Javascript and DOM, but not jQuery or Ajax (but I'll do what I must to get it working.)

Topological Sort
  • 2,733
  • 2
  • 27
  • 54
  • 1
    AJAX call would be the cleanest way, in my opinion. Both acceptable, but in the second way you are creating waay too much information you might not ever use. – alxgb Mar 27 '13 at 18:37
  • You're teaching a class on something you don't know will work? – Michael Mar 27 '13 at 19:00
  • But the first you are adding complexity of a php script that returns an individual cal event in whatever format, and js that translates that into a dom object. – Tyson of the Northwest Mar 27 '13 at 19:25
  • 1
    Yes, in technology-related disciplines, we do have to keep learning! Here's sample code to do a simple AJAX call to load a PHP file (see first answer): http://stackoverflow.com/questions/7165395/call-php-function-from-javascript – Topological Sort Mar 27 '13 at 21:27

1 Answers1

0

An Ajax call on mouseover gives you the ability to refresh modal window content between displays, as every time it mouses over it fires off an query for that window's content and you only get the data you specifically look at. But, you not only need a php script to generate the calendar, but also to return the individual event data in whatever format (xml,json,ical) and interpret that into content.

Hidden modal windows require only one php script and no Ajax calls. But you get more data then you may use.

I would advise the second option unless you are teaching a class on client/server models, translating data formats, and Ajax.

Tyson of the Northwest
  • 2,086
  • 2
  • 21
  • 34