Jump to content

Reusing Common content


gevensen

Recommended Posts

I have some routines I use over and over

Is there a way to put the error section in a file of its own

 

For example I use a routine below

 

<script type="text/javascript">
$('.MYTRIGGER').live('change', function() {
     
            var MyData=''; $("#jq_tab").val('0');
         var NameData=$(this).attr('name');
         var IdData=$(this).attr('id');
          MyData=MyData+'CID='+NameData;;
         MyData=MyData+'&Field='+IdData;
         MyData=MyData+'&FieldValue='+$(this).val();
                    


           
    $.ajax( { 
        cache:false, 
        timeout:28000, 
    url : 'MyPhp.php',
    type : 'post',
    data : MyData,
    success : function( resp ) {   
$("#jq_tab").val('1');


    
    


       return(false); 




    },


    error: function(xhr, status, error) {
        var stat = $("#jq_tab").val();
    $("#main_page_div").unmask_div();
    if(stat!='1'){
     if (xhr.status === 0) {
                    alert('Unable to connect to Network');
                } else if (xhr.status == 404) {
                    alert('Requested page not found. [404]');
                } else if (xhr.status == 500) {
                    alert('Internal Server Error [500].');
                } else if (exception === 'parsererror') {
                    alert('Requested JSON parse failed.');
                } else if (exception === 'timeout') {
                    alert('System Timeout (Internet Congestion or server slow)');
                } else if (exception === 'abort') {
                    alert('Ajax request aborted.');
                } else {
                    alert('Unspecified Error #' + xhr.responseText);
                }
    }
    return false;
    } // eof error function
    
    
    });  
       
            


        


});
</script>

Since the below is common

 

error: function(xhr, status, error) {
        var stat = $("#jq_tab").val();
    $("#main_page_div").unmask_div();
    if(stat!='1'){
     if (xhr.status === 0) {
                    alert('Unable to connect to Network');
                } else if (xhr.status == 404) {
                    alert('Requested page not found. [404]');
                } else if (xhr.status == 500) {
                    alert('Internal Server Error [500].');
                } else if (exception === 'parsererror') {
                    alert('Requested JSON parse failed.');
                } else if (exception === 'timeout') {
                    alert('System Timeout (Internet Congestion or server slow)');
                } else if (exception === 'abort') {
                    alert('Ajax request aborted.');
                } else {
                    alert('Unspecified Error #' + xhr.responseText);
                }
    }
    return false;
    } // eof error function

Is there a way to store the error function in a common file?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.