javascript - Controller returns plain json data instead of staying on page -


I am trying to request an AJAX request to return the search results. When I submit a search, my Jason data comes back to my white black and white page. How do I keep it on page and exclude the rest of JavaScript? I suspect that the problem is either event.preventDefault is not working properly or the code return in the controller is preventing anything from happening.

Here are my code snippets:

HTML

  & lt; Div id = "contactform" & gt; & Lt; P & gt; Search for contacts & lt; / P & gt; {{Form :: open (array ('route' = & gt; 'contact.results', 'method' = & gt; 'post', 'id' => 'contactsearchform'))}} {{form :: text ('Contactsearch', null, array ('id' = & gt; 'contactsearch', 'placeholder' = & gt; 'name'))}} & lt; Button type = "submit" & gt; Search & lt; / Button & gt; {{Form :: off ()}} & lt; / Div & gt; & Lt; Div id = "search_results" & gt; Search results & lt; Table cellpadding = "0" selection = "0" range = "0" & ​​gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Td class = "name first" & gt; Name & lt; / Td> & Lt; Td class = "phone" & gt; Phone & lt; / Td> & Lt; Td class = "email" & gt; Email & lt; / Td> & Lt; Td square = "lot" & gt; Lot & lt; / Td> & Lt; Td square = "last edit" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Td class = "name first" & gt; & Lt; A href = "#" class = "contact" & gt; & Lt; / A & gt; & Lt; / Td> & Lt; Td class = "phone" & gt; & Lt; / Td> & Lt; Td class = "email" & gt; & Lt; / Td> & Lt; Td square = "last edit" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt;   

JavaScript

  $ ('contactsearchform'). Submit (function (event) {event.preventDefault (); var data string = $ (this) .certisize (); console.log ('submitted data: \ n' + data string); $ .gend ({type: "Post", url: "/ contact" results, data: datestring, error: work () {console.log ("something is wrong, please notify administrator");}, success: function (result data) {console. Log ('result data: \ n' + result data); resultsData = $ .resultData; console.log ('parse data: \ n' + resultDataP); if (resultDataP.table) {$ ('# search_results' ) Html (resultDataP.table); $ ('# search_results'). $ ('# Contactsearchform input'). Blur ();} else {console.log ("Something was not working.");} }}); Return;});   

Administrators

  public function showSearch () {return view :: create ('portal.search'); } Public function doSearch () {// search for contacts here $ search = input :: get ('contactsearch'); $ Contact = db :: table ('contact') - & gt; Where ('last_name', 'likes', "$ search") - & gt; get (); If (count ($ contact)! = 0) {$ response = ['status' = & gt; 'Success', 'msg' = & gt; 'Contact matches your search', 'result' = & gt; $ Contact]; } And {$ response = ['status' = & gt; 'Error', 'msg' = & gt; 'No contact matches your search.' ]; } Return response: Jason ($ reaction); }   

and my routes

  // Search for contacts Route: Receive ('/ portal / contact' , Array ('as' => gt; contact' search ',' usage '= & gt; PortalController @ showSearch')); Root :: Post ('/ portal / contact', array ('as' = 'gt;' contact result ',' usage '= & gt; portal controller @ doSearch'));    

You should change your javascript things like using the following / ** Consider the hash before the ID of the form that you have not added to the form so as not to consider the form, you also need to change the URL $ .Ajax call url: '/ portal / contact 'Because jquery does not understand the name of the larval route ** / $ (' # contactsearchform '). Submit (function (e) {........});

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -