开发者

Textarea to refresh using jQuery/MySQL

OK so let's say I have a textarea on the top of my browser and a text input box on the bottom. I want to connect a MySQL database and al开发者_运维知识库so whatever I type in the input box to appear in the text area. Sorta like a text RPG...

I know PHP, MySQL, good AJAX, and little jQuery. I just want to know how this is achieved. Thank you.


You can do something like this (the code below sends input text to php script which connects to database, does whatever you want it to do and prints a text to be displayed in text area) :

$("#update_btn").click(function() {
    var txt = $.ajax({
    url: 'your_file.php',
    async: true, // or false, depends on your needs
    type:'POST',
    data:({new_text:$('#input_box_1').val()})
     }).responseText;

     $('#txt_area_1').val(txt);
    });

To access new_text variable in php script, use $new_text = $_POST["new_text"]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜