Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function showSpinner()
- {
- $('#resultsArea').html('<img src="img/new_spinner.gif">');
- }
- function isIE()
- {
- var undef,
- v = 3,
- div = document.createElement('div'),
- all = div.getElementsByTagName('i');
- while (
- div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
- all[0]
- );
- return v > 4 ? v : undef;
- }
- function handleUpload()
- {
- showSpinner();
- var dFile = new FormData(document.getElementById("devConsValidate")); // this works in IE but only if called by a submit method
- $.ajax(
- {
- cache: false,
- async: false,
- url: 'validator.php',
- type: 'POST',
- data: dFile,
- dataType: 'JSON',
- processData: false, // this is key for formdata
- contentType: false, // so is this
- success: function(response)
- {
- var result = response.result;
- var validationCode = response.validation_code;
- var errors = response.errors;
- var htmlCode = '<h2>';
- if (result == 'SUCCESS')
- htmlCode += '<font color="green">';
- else
- {
- htmlCode += '<font color="red">';
- }
- htmlCode += 'Validation ' + result + '</font></h3>';
- if (result == "FAIL")
- {
- htmlCode += '</center>';
- for (var i in errors)
- htmlCode += errors[i] + '<br>';
- htmlCode += '<br><a href="validator_help.php">Validator Help</a>';
- }
- else
- {
- htmlCode += 'Please use the following code when submitting your request.<br><br><font color ="#00aa54" size="+2">' + validationCode + '</font>';
- }
- // make some beautiful html
- $('#resultsArea').html(htmlCode);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown)
- {
- alert('error: ' + errorThrown);
- }
- });
- }
- $(document).ready(function()
- {
- if (isIE() != undefined)
- {
- $('#devConsValidate').submit(function()
- {
- handleUpload();
- return false; // dont really submit because we already did
- });
- }
- else
- {
- $('#fileBox').change(function() // this doesnt fire in IE
- {
- handleUpload();
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement