3 Replies - 1971 Views - Last Post: 24 April 2014 - 04:45 PM

#1 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 174
  • Joined: 07-October 12

Trying to display error message with Div instead of js popup

Posted 24 April 2014 - 11:49 AM

So I decided that displaying a user a div with error information would be more aesthetically pleasing than to have a JS popup. I'm having two issues with this method. One is that if I use the form standardly it shows all the correct information from the information put into the form. IE
My db_connection.php page is as follows
<?php
echo $_GET['db_url'];
echo $_GET['db_port'];
echo $_GET['db_name'];
echo $_GET['db_user'];
echo $_GET['db_pass'];
?>


Works fine with I have the form action set but when I try to use Jquery to reload the div it displays that it's an undefined variable instead of the information put in from the form.
My Jquery is as follows
<script>
$(document).ready(function(){
  $("#test_connect").click(function(){
    $("#ConnectMessage").load("functions.d/db_connection.php");
	return false;
  });
});
</script>


I thought that maybe my return false statement was preventing the php script from running in the background, but if I remove it than the page will just refresh itself. Kind of stumped at this point.

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to display error message with Div instead of js popup

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: Trying to display error message with Div instead of js popup

Posted 24 April 2014 - 12:13 PM

PHP can't display anything. Topic moved to jQuery.
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 399
  • View blog
  • Posts: 1,455
  • Joined: 15-January 14

Re: Trying to display error message with Div instead of js popup

Posted 24 April 2014 - 12:51 PM

The PHP script is looking for things in $_GET, but your ajax request does not send any values there.
Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: Trying to display error message with Div instead of js popup

Posted 24 April 2014 - 04:45 PM

Also it should be noted that PHP will only return the last echo to the Ajax call.


Here is the Idea
var data = {
db_url: "url/to/use", 
db_port: "8080",
db_name: "someDBName",
db_user: "someDBUser",
db_pass: "someDBPass"
}

$(document).ready(function(){
	  $("#test_connect").click(function(){
	    $("#ConnectMessage").get("functions.d/db_connection.php", data, function(returnData){
               //Do stuff with returnData as json data
            });
	    
	  });
	});


<?php
echo json_encode($_GET);
?>


This post has been edited by laytonsdad: 24 April 2014 - 04:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1