jquery - Ajax Error Function Not Firing -
My function is fully executed while being displayed, however, when there are no results or, in my case To display program host records, I want to display a message for "No results". However, nothing happens. any idea? Thanks for the help!
$ ('#search'). Click (function () {var form_data = $ ('# verification-form'). SerializeArray (); $ .ajax ({Url: "& lt ;? php echo site_url ('opportunity / search_existing_program_host') ;? & Gt ; ", Type: 'post', data: form_data, cache: wrong, success: function (server_proc) {var data = $ .parseJSON (server_response); html = '', program_host; html + '' TR & gt; & lt; th & gt; Program host name & lt; / or & gt; & lt; th & gt; location & lt; / th & gt; & lt; th & gt; session prefix & lt; / Var / i & lt; th & gt; Agency no. & Lt; / th> & lt; / tr & gt; '; var i = 0; i & lt; data lamps; i ++) {program_host = Data [ I]; html + = '& lt; tr & gt;; & lt; td & gt;' + program_host.program_host_Name + '& lt; / td & gt; & lt; td & gt;' + program_host.Address_1 + ',' + Program_host.City + ',' + program_host.State + ' gt; & lt; td & gt;' + program_host.Session_Number_Prefix + ' gt; & lt; TD & gt; '+ program_host.Agency_Number +' & lt; / td & gt; & Lt; / TR & gt; ';} $ ('# Existing_program_hosts') attached (html);}, error: function () {// warning ('error'); Var html = ''; Html + = '& lt; Tr & gt; & Lt; Th & gt; No Results & lt; / Th & gt; & Lt; / Tr & gt; '; $ ('#existing_program_hosts') Attached (HTML) }}); $ ('# Create_Host_btn') Show (). }) My job is to return the results here:
function_existing_program_host () {$ Program_Host_Name = $ this- & gt; Input-> ('Program_Host_Name'); $ Address = $ this- & gt; Input-> Post ('address_1'); $ Program_hosts = $ this- & gt; Ion_auth_model- & gt; Search_xing_program_host ($ program_host_name, $ address1); Foreach ($ program_hosts as $ program_host): $ result [] = array ("Program_Host_Name" => gt; "$ program_host- & gt; name", "Session_Number_Prefix" = & gt; "$ program_host-> Session_Number_Prefix "," Agency_Number "= & gt; $ $ program_host- & gt; agency_number", "address_1" = & gt; "$ program_host- & gt; address1", "address_2" = & gt; "$ program_host- & gt; = "$ Program_host -> ZIP_CODE", "Primary_Phone_Number" => "$ program_host-> Primary_Phone_Number", "Secondary_Phone_Number" => "$ program_host- & gt; ==> "$ program_host- & gt; Fax_Number", "number_01_3" => "$ program_host-> number_01-c3", "end I01c3" =>
" $ Program_host- & gt; Termination I 01c3 "," city "=> gt;" $ program_host- & gt; city "," state "= & gt;" $ program_host- & gt; state "); Endforeach; Echo json_encode ($ result); }
Personally, I do something like this:
SerializeArray (); Var html = '& lt; Tr & gt; & Lt; Th & gt; No results & lt; Click the $ ('# lookup') (function () {var form_data = $ ('# verification-form'). Th & gt; & lt; / tr & gt; $ .ajax ({ Url: "& lt ;? php echo site_url ('opportunity / search_exing_program_host') ;? gt;, type: 'post', data: form_data, cache: false, success: work (server_press) {var data = $. ParseSSE (server_proson); var program_host; if (server_process! = Null) {html + = ' th & gt; program hostname Agency no. & lt; / tr & Gt; (Var i = 0; i & lt; data.length; i ++) {program_host = data [i]; html + = ' & lt; ; Td> '+ program_host.Session_Number_Prefi X +' & lt; / td> & lt; td & gt; '+ program_host.Agency_Number +' & lt; / Td> & Lt; / Tr & gt; '; }}}, Error: function (E, textstats) {// Maybe you want something a little bit more custom here? Html + = '& lt; Tr & gt; & Lt; Th & gt; + Textstat ++ & lt; / Th & gt; & Lt; / Tr & gt; '; }, Completed: Work () {$ ('# existing_program_hosts'). Attachment (html); }});
Comments
Post a Comment