Skip to content Skip to sidebar Skip to footer

How To Send Post Data With Jquery Ajax To Php Function

I want to send POST request with jquery AJAX to PHP function but it don't give any respond. JQuery $.ajax({ url: 'ListProduk.php/SelectData', type: 'POST', success: fun

Solution 1:

When not using url rewriting (google mod_rewrite and pretty URL's), your parameters typically are going to be passed as a normal HTTP GET request. Here is an example of how your URL structure might look:

url:'ListProduk.php?action=SelectData'

And then, in your PHP, you might handle it based on the action that is requested (Note: The action parameter is not something specific to web development, it's just an arbitrary name I assigned. It could be foo=SelectData as well)

if ($_POST['action'] == 'SelectData') {
   // Run the code for selecting data
}

Finally, you wouldn't want to "return" the JSON data. You need to output it with the correct headers. It would look something like this:

header('Content-Type: application/json');
echo json_encode($data);

Post a Comment for "How To Send Post Data With Jquery Ajax To Php Function"