I’m trying to use jQuery to send an input to be processed on another page but I’m having some trouble getting it to work.
When I open up the network console I can see a GET method set to common_functions, but there’s no variables attached to it. I’m getting this
http://localhost/project/common_functions.php
instead of something like
http://localhost/project/common_functions.php?name=abcdef
Here’s my HTML. It’s fine as far as I know because I get an alert from the function receiving the input
<form method="post">
<table>
<tr><td>Project Name</td><td><input type = "textbox" name="project_name" id = "project_name" onkeyup = "get_name(this.value);" /></td></tr>
<tr><td>Project Description</td><td><input type = "textbox" name="project_name" id = "project_description" onkeyup = "get_description(this.value);"/></td></tr>
<tr><td><input type="submit" name="submit_project"></td></tr>
</table>
</form>
Here’s the jQuery. I’m attempting to send a GET request.
function get_name(name){
var project_name = name;
$.get('common_functions.php', function(name) {
alert(project_name); //this displays the name
$('#project_name').html(name);
});
}
When I have just this I get an alert, so I know it’s at least acknowledging the onkeyup.
You are not sending any data. You can either append the data to the script name or send it as key – value pairs:
And I would not use the same variable name in the callback function, that only leads to confusion.