Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnClick Send To Ajax

I'm trying to complete some ajax requests to insert a textarea into a database without refresh. Here is my code:

HTML:

<textarea name='Status'> </textarea>
<input type='button' onclick='UpdateStatus()' value='Status Update'>

JS:

function UpdateStatus(Status)
    {
    var Status = $(this).val();

        $(function()
        {
            $.ajax({
                url: 'Ajax/StatusUpdate.php?Status='.Status, data: "", dataType: 'json'
            });

        });
    }

My Questions:

1) How do I send the contents of the text area into the onclick function?

2) How do I escape/urlencode etc.. So it retains line breaks

like image 790
Sophie Mackeral Avatar asked May 25 '13 21:05

Sophie Mackeral


People also ask

How can make AJAX call in jQuery?

The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.

How AJAX call in react JS?

APIs are used for fetching data from the server and using AJAX and API we call data asynchronously and show it in our HTML. You can make API requests by using browser build in fetch function or third party libraries like Axios.


1 Answers

<textarea name='Status'> </textarea>
<input type='button' value='Status Update'>

You have few problems with your code like using . for concatenation

Try this -

$(function () {
    $('input').on('click', function () {
        var Status = $(this).val();
        $.ajax({
            url: 'Ajax/StatusUpdate.php',
            data: {
                text: $("textarea[name=Status]").val(),
                Status: Status
            },
            dataType : 'json'
        });
    });
});
like image 190
Mohammad Adil Avatar answered Oct 06 '22 09:10

Mohammad Adil