jeudi 1 janvier 2015

PHP data in AJAX success?


I'm trying to run a very basic PHP code via AJAX and get the data back from PHP page into AJAX success.


however, I don't get anything in the AJAX success from the PHP page and its bugging me badly.


this is the AJAX code:



$(document).ready(function(){
$(function(){
$('#form-post').on('submit', function(e){

// prevent native form submission here
e.preventDefault();

// now do whatever you want here
$.ajax({
type: $(this).attr('method'), // <-- get method of form
url: $(this).attr('action'), // <-- get action of form
data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
beforeSend: function(){
//$('#result').html('<img src="loading.gif" />');
},
success: function(data){
$('#messageme').html(data);
}
});
});
});
});


and this is the Form:



<form id="form-post" action="post-code.php" method="post" >
<input type="hidden" value="Post" name="submit" />
<input type="text" class="inp-form" name="postcode" id="postcode" placeholder="Enter Post Code " /><br /><br /><input type="text" id="messageme" /><br /><br />
<input id="findAd" type="button" value=" Search For Address" />
</form>


and a very simple php:



<?php

$street = "some";
echo $street;
?>


could someone please advise on this?





Aucun commentaire:

Enregistrer un commentaire