Reputation: 1111
I am trying to send an ajax
request using jquery.
this is my code:
$(".del-link").click(function() {
var del = confirm("sure you want to delete?");
var ID = $(this).attr('id');
}).change(function() {
var ID = $(this).attr('id');
var del = $("#del_input_" + ID).val();
var dataString = 'id=' + ID;
$("#status_" + ID).html('<img src="load.gif" />');
console.log(dataString);
if (del == true) {
$.ajax({
type: "POST",
url: "../inc/deleteRow.php",
data: dataString,
cache: false,
success: function(html) {
$("#del_" + ID).html(del);
}
});
} else {
alert('not deleted');
}
});
I am sending the request to ../inc/deleteRow.php
url.
in that url are several functions.
how do I send the data
content to a specific function in that file?
edited:
this is the content of the deleteRow.php
file:
as you can see there are several functions
<?php
if($_POST['id'])
{
$update = new User();
$update->update($_POST['id'], $_POST['lead_status'], $_POST['lead_comment']);
}
{
$update = new User();
$update->updatecall($_POST['id'], $_POST['lead_status'], $_POST['lead_comment']);
}
$delete_row = new User();
$delete_row->delete_row($_POST['id']);
?>
Upvotes: 0
Views: 53
Reputation: 218960
JavaScript doesn't know anything about the server-side code.
In the server-side code (PHP in this case) you would respond to the request given the information provided in the request. So given the state of the request being made (the URL, the HTTP verb, most likely the combination of POST values in your case, etc.) the logic in your PHP code would determine what to do.
Ideally you wouldn't have a single URL which does many things. Instead, you'd have separate URLs (or "resources") which each do one thing (or one small related subset of things). Preferably something intuitively named.
But any way you look at it, you don't "call a PHP function" from JavaScript. You send an HTTP request, just as you're already doing. Then in your server-side code you would respond to that HTTP request using whatever logic your application needs to use.
Upvotes: 1