function downloadProduct( prodGuid ) { var link = "#link_" + prodGuid; $( link ).html( "Download Initiated" ); $.get( "includes/ajax/getdownloads.php", { action: "getdownload", guid: prodGuid }, function( data ) { // no constants here. this is the only place. here are some return codes: // -1: guid parameter is empty // -2: no rows in result set // -3: root directory not set in database // -4: file doesn't exist. // -5: mkdir failed var emsg = ""; // all the errors here. switch( data ) { case "-1": emsg = neucart_dp_param_missing; break; case "-2": emsg = neucart_dp_no_file; break; case "-3": emsg = neucart_dp_no_root_dir; break; case "-4": emsg = neucart_dp_file_loc_missing; break; case "-5": emsg = neucart_dp_failed_create_url; break; case "0": // go below break; default: emsg = neucart_dp_general_error; break; } // no error? if ( data == "0" ) { // full path excluding id var path = 'downloadfile.php?guid='; var url = path + prodGuid; window.location= url; } else { $( link ).html( emsg ); } }); }