Reputation: 263
I would like to submit some data. Weather this be using a form, or onClick
execute some AJAX, I'm not sure.
For example, I have this input
<input id='inpamount' type="text" name="amount" value="2.00" onkeyup="pad();validatemin();product()">
Now say if I wanted to send this data to a PHP file, using post ( i could just add a form). But then, without reloading the page (I can do this), how could I fetch a response (using AJAX).
Essentially I would like a user to be able to press a button, then to submit the inputs to a php file, and then get the output and assign it to a variable (I know how to do this, I just want to be able to get the data.
The php execute takes a few centiseconds because it comunicates with SQL. (If this matters).
I have considered using invisible forms but it didn't seem to work
If anyone could point me in the right direction, that would be great.
Upvotes: 0
Views: 44
Reputation: 24565
Something like this?
$(document).ready(function(e) {
$('#inpamount').click(function() {
var data = 'myValue=' + $(this).val();
$.ajax({
url: "yourscript.php",
type: "POST",
data: data,
cache: false,
success: function(scriptOutput) {
//handle the result
}
}
});
return false;
});
});
Upvotes: 1