How to do a HTTP PUT/DELETE? (Using jquery) . Im making a REST-ful twitter-type aplication using Java Servlets etc... and i have the methods for handling PUT and DELETE, i just need to be able to perform these e.g. when a user submits a form (with the id of the tweet to be deleted, for example). However, forms only support the methods POST and GET hence i was instructed to use jquery, which i am unfamiliar with. Can anyone help me?

Hi jbennet,

Go download the latest version of JQuery ( and include this (the downloaded file) in the '<head>' of your site.

Next, create a file called delete.js file with the following 'post' request - and include it on your page.

function delete_item(id) {	
	/* Post the id of the item you want to delete */
	$.post("action.php", { delete_id: id }, 	
	function(data) {
		/* Receive the data from your php file */
		var db_response = eval('(' + data + ')');
		/* Alert the response */

Then create a file called action.php file that handles the deletion of your items. The output from this file will be picked up by the delete.js file, so you can either show a success or an error message.

/* Delete your item using a MySql statement, then output one of the following: */

/* Success! */
//echo json_encode( array('success') );

/* Error :( */
//echo json_encode( array('error') );

Then put it all together like this:

<!-- This is the JQuery file you downloaded -->
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<!-- This is your file that posts a request to your php file -->
<script type="text/javascript" src="delete.js"></script>
<a href="#" onclick="delete_item(2); return false;">Click here</a> to delete item #2

I hope this helps you out.

Jim :)

commented: thanks +25
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.