Reputation: 137
I want to pass two input data to PHP with JQuery ajax I read about json, serialize and similar but I couldn't quite get a grip around it. I got:
<p><input type="text" id="domain"></p>
<p><input type="text" id="domain1"></p>
<button id="order">Search</button>
<script type="text/javascript">
function callAjax() {
$.ajax({
type: "GET",
cache: false,
url: 'getip.php',
data: ???
});
</script>
And also what do I need on PHP file because I only got this.
$name=($_GET['']);
$surname =
echo($name) ;
endif;
Upvotes: 0
Views: 89
Reputation: 1226
$.ajax({
type: "GET",
cache: false,
url: 'getip.php',
data = {
'domain': $('#domain').val(),
'domain1': $('#domain1').val()
};
)};
And in you php file php you can get data with :
$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];
Upvotes: 2
Reputation: 72269
Try this:-
<p><input type="text" id="domain" name = "domain"></p>
<p><input type="text" id="domain1" name ="domain1"></p>
<button id="order">Search</button>
function callAjax() {
$.ajax({
type: "GET",
cache: false,
url: 'getip.php',
data:{domain: $('#domain').val(),domain1: $('#domain1').val()}
});
In your php file get it like this:-
$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];
Note:- Please try to read jquery a bit. It will help you.
Upvotes: 1
Reputation: 87233
function callAjax() {
// Get values to send to server
var domain = $('#domain').val();
var domain1 = $('#domain1').val();
$.ajax({
type: "GET",
cache: false,
url: 'getip.php',
data: {
domain: domain,
domain1: domain1
}
And in php you'll get it as
$domain = $_GET['domain'];
$domain1 = $_GET['domain1'];
Docs: http://api.jquery.com/jQuery.ajax/
Upvotes: 2