Skip to content Skip to sidebar Skip to footer

How To Post Data With JQuery

I'm using PHP to submit a very simple data to db. On my page.php, I have a link, by clicking it I insert its id and some other data in the database. For example: echo '
 $.ajax({
  type: 'POST',
  url: page.php,
  data: submit=$page_id,
  success: function(){print("success");}
});

btw: it is better to use post than get, it just looks cleaner. (at least in my opinion)


Solution 2:

Youll need to use a ajax method as per CyrillC's answer. here is the official docs ajax jquery

(there is a shortcode for using the POST method)

$.post.({ etc

the post method hides your data from the browser (get puts it in the query string) so its cleaner but also better for security


Solution 3:

<a href="#" onclick="$.post(
    '<?php echo $base_url ?>',
    { submit= '<?php echo $page_id ?>'},
    callback_function(data)
)">Submit it</a>

Send a post request to php, and deal with the message ( "data" ) with javascript?


Solution 4:

You will need to use AJAX with jQuery. For starters, have a look at the functions load , get and post here . The methods get and post are the ones used to submit the data to server-side scripting , since you are using GET method in PHP , use GET of AJAX


Post a Comment for "How To Post Data With JQuery"