2

Basically, I want to have an interactive button on my website, that, when clicked, sends some data to the server in order to be checked and display the response (without form sending / page reload).

I thought it would be something like:

function checkData()
{
    var req = new XMLHttpRequest();
    var conf = document.getElementById('my_text_area').value;

    req.open("GET", 'check_data', true);
    req.onreadystatechange = function () 
    {
        var pre = document.getElementById('check_data_out');
        pre.innerHTML = req.responseText;
    }

    req.send(conf);
    return false;
}

And on the server side:

@get('/check_data')
def check_data():
    # Process the content and answer something...
    content = str(request.is_ajax) + ' - ' + str(request.GET) + ' - ' + str(request.POST)
    return content

But this obviously doesn't work. Either it is not the right way to send data via javascript or not the right way to access it in bottle.py.

Showing me how it works is highly appreciated.

4

1 回答 1

0

您可以将 dojo 用于客户端逻辑。

var button = dojo.byId('button_id'); // button_id refers to the id of the button you want to click

dojo.connect(button,'onclick',dojo.xhrGet({
   url: '/check_data',
   handleAs : 'text',
   load : function(response){
       dojo.byId('button_id').innerHTML = response; 
   }
}));
于 2011-04-28T11:08:29.887 回答