views:

90

answers:

2

I have a programm where i get the values of two variables for example x and y using javascript functions.How can i send them to the django server so as to do something(for example search in the database for matching values).How can i do this "SENDING" thing.Which language should i use for example?

+1  A: 

You should use JQuery for that.

You can send your variables with this function :

$.post('theUrlOfYourView', {'x': x, 'y': y})

After that you can get this variables in your view with the request.POST object. You just have to return a HttpResponse() object at the end of your view.

nicknick63
A: 

There are two ways to send the data from HTML form to the server. One is by submitting the form, and the other is using an asynchronous request.

The first one is easier. The easiest thing is to simply include a "submit" button in your form. This will send the request to the server without you having to write even one line of code. Here some basic info about that.

The drawback of this method is that it will result in loading a new page - you can't change the existing page. If you want to use the result to update the current page - than you need an asynchronous request.

Asynchronous request are sent using JavaScript. It is not awfully complicated, but it is made much easier if you use a JavaScript library, such as JQuery. I think the AJAX chapter in the "JQuery in Action" book might help you.

Daphna Shezaf