Calling an ajax function from an event handler

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Calling an ajax function from an event handler

L Jay
I have several places in my jQuery code where I need to call the .ajax method.  To avoid duplication, I have created a function to process the .ajax call.  However, after I extracted the .ajax code to it's own function, the .ajax does not seem to be getting called.
Can anyone see a problem with the way I declared my function below?

<script type="text/javascript"> function processAjax(msg, errorMsg, durl, theElement, data) { $.ajax({ url: durl, beforeSend: function() { $.blockUI({ message: '<h1><img src="/media/default/admin_panel/images/busy.gif" />'+msg+'...</h1>' }); }, success: function( data ) { if (data){ theElement.html( data ); } else{ $('#results').block({ message: '<h1>'+errorMsg+'</h1>', css: { border: '1px solid #a00',color:'red'}, timeout: 2500 }); } } }); } $(function() { $('#sis_student_list').change(function(){ q = $( '#sis_student_list' ).val(); durl = '{% url get_sis_student %}?q=' + q; var theElement = $( '#selected_sis_student_details' ); msg = 'Getting Student Details'; errorMsg = 'Error Getting Details of Selected Student.'; processAjax(msg, errorMsg, durl, theElement, data); }); }); </script>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling an ajax function from an event handler

ArgyleGhost
This site mite help you find bugs in your javascript/Ajax Code:
http://www.jslint.com/
Loading...