Ajax returning [object Object]

3

HTML

index.html

<!DOCTYPE html>
<html>
	<head>

		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><scriptsrc="script.js"></script>
		<link href="css/refreshform.css" rel="stylesheet">

	</head>
<body>

	<div id="mainform">
		<h2>Submit Form Using AJAX and jQuery</h2> 
		<div id="form">
			<h3>Fill Your Information !</h3>
			<div>
				<label>Email :</label>
				<input id="email" type="text">
				<label>Password :</label>
				<input id="password" type="password">
				<input id="submit" type="button" value="Submit">
			</div>
		</div>
	</div>

</body>
</html>

JavaScript

script.js

$(document).ready(function(){
	$("#submit").click(function(){
		var name 		= $("#name").val();
		var email 		= $("#email").val();
		var password 	= $("#password").val();
		var contact 	= $("#contact").val();

		var dataString = '&email1=' + email + '&password1=' + password;
			if(email == '' || password == '' )
			{
				alert("Por favor preencha todos campos");
			}
			else
			{
				$.ajax({
					type: "POST",
					url: "http://192.168.0.10/apps/ajaxsubmit.php",
					data: dataString,
					datatype: 'json',
						success: function(data){
							$('#result').html(data.status +':' + data.message);   
            				$("#result").addClass('msg_notice');
            				$("#result").fadeIn(1500);  
						}
				});
			}
		return false;
	});
});

PHP

ajaxsubmit.php

<?php
header('Content-Type: application/json');
$connection = mysql_connect("localhost", "root", ""); 

$db = mysql_select_db("mydba", $connection); 

$email2     =   $_POST['email1'];
$password2  =   $_POST['password1'];

$query = mysql_query("SELECT * FROM form_element WHERE email = '" .mysql_real_escape_string($email2). "' AND password = '" .mysql_real_escape_string($password2). "' ");

$num_row = mysql_num_rows($query);

if($num_row>0)
{

     echo json_encode(array('status' => 'success','message'=> 'The group has been removed'));

}else{

     echo json_encode(array('status' => 'success','message'=> 'The group has been removed'));
}

mysql_close($connection); 

What is returning:

    
asked by anonymous 20.08.2016 / 21:09

2 answers

0

This has a quick response, the alert that was made does not resolve the object to string, so you have to give console.log(); to see the message received in the object which will be something like this:

[status: 'success', message: 'qll coisa']

To access one of the elements, this is enough:

data.message
    
20.08.2016 / 22:16
0

Transform into JSON:

alert(JSON.stringify(data));

console.log(JSON.stringify(data));

    
21.08.2016 / 14:09