开发者

Making posts and storing them using AJAX

I was given a suggestion for my web app as follows:

You'll want to do an AJAX POST with the text and the annotation position to save the data on the server, so you'll to have a URL in your app that can accept those.

Basically, I have a JS script running that gets selected text on the page and posts it into a particular div. I want, however, to get that text to store in my database, if I could.

How do I go about doing that? I was recently going through this one: How to Make a Feed From User Submitted Posts ...

It didn't quite get me where I wanted, though. For good measure, here is the JS script I am using to get the selected text off the page.

 <script type="text/javascript">
    <!--
        function getSelText()
    {
    var txt = '';
    var foundIn = '';
        if (window.getSelection)
        { 
        txt = window.getSelection();


    }
        else if (document.getSelection)
        {
开发者_如何学Go        txt = document.getSelection();

    }
        else if (document.selection)
        {   
        txt = document.selection.createRange().text;

    }
        else return;
        document.aform.selectedtext.value =  txt;
    }
    // -->
    </script>


As the suggestion has mentioned earlier, you'd need to do an AJAX post to the server where your serverside script is running. Your server side script shall have a url, for example: http://www.example.com/saveselection.php. You can read up about ajax post in basic javascript or in jQuery docs. You should know some server scripting to save the selected posted in your preferred language.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜