Tuesday 15 January 2013

javascript - Prevent PHP showing results in new page -


I'm trying to get a PHP file to collect directory information, Display it on the page.

My HTML code is as follows:

  & lt; Form id = "myFormName" method = "post" action = "PHP_function.php" & gt; & Lt; Input type = "submit" class = "learnButton" name = "insert" value = "find available evidence" /> & Lt; / Form & gt; & Lt; Script & gt; $ (Function () {$ ("(MyFormName"). Submit (function) {event.preventDefault (); $ .ajax ({type: "POST", url: $ (this) .attr ('action' ), Data: $ (this) .rerealize (), datatype: 'jason', success: function (data) {// display data ... // ("#results"). Html (data.name) .show ; //console.log (data); $ ("# result"). Append (data.name);}});});}); & lt; / script & gt; & lt; div id = " The result will be my main HTML page ( IfPresentArray ) and " On which I have tried, there is an array to post:  
  echo json_encode ($ IfPresentA Rray);   

In addition, this code gives me the exact result, but I want them to be written to "result" div and Do not open a new PHP page with results

I think I want to use JSON and AJAX Please post results back to the page, but I'm struggling to do this and really appreciate some help.

Firstly, stop the form from requesting an HTTP request. As a failure in Javascript, this will mean that the return statement will never reach and the form HTTP request will fire.

 < $ ("# myFormName" / code>) AJAX ({type: "post", url: $ (this) .attr ('verb'), data: $ (this) .rerealize (), datatype: 'jason', // This is what you get from PHP (ie JSON, HTML, etc.) Expect the success of: Function (Data) {// Data Your Jason Array or Object Console.log (date // will allow you to see the return data in the web browser inspection tool $ ("# result") .andend (data.name) Show; (); // show is a function (only if you have the result Then you need to hide it.}});  

Then just check the brackets on the rest of your Javascript matches. Simply use a program with syntax highlighting.


No comments:

Post a Comment