$(document).ready(function(){
$("form#fbox")开发者_运维百科.submit(function(){
var msg = $("input#ibox").val();
$.get("foo.php", {m: msg}, function(data){
$('#display').html(data);
});
return false;
});
});
i have this jquery script wherein it creates a post request "invisibly" after submitting the form. thus not refreshing the page. the problem is how can i get the response of the foo.php or rather what will i put in foo.php to give back a response?
for example i inputted 'hello', how can i display 'hi' on #display? something like that xD
You would have foo.php
echo whatever content you want to go inside the element that corresponds to #display
-- no more, no less. So this would work:
echo 'hi';
Put whatever you need in foo.php. The contents of that html page will be placed into #display.
You're already setting the contents of #display
to whatever the script outputs.
The 3rd argument to $.get
is a callback which is execute on success.
In your php file you should echo anything you want to return. So if you want your response to say 'Hello World' your php file would look like:
<?
echo "Hello World";
?>
Your JavaScript looks like it is handling it properly.
精彩评论