Q:

Can i use ajax inside JavaScript? I have used it but doesn't work

I have used AJAX inside JavaScript where I want to send a few parameters and set the button value from lock to unlock when a certain condition is true. But it doesn't work, I mean it doesn't go to AJAX.
Here is my code, which is being called with a button onclick function:
<script type="text/javascript">
    function change() {
        var elem = document.getElementById("lockId");
        var orderid = document.getElementById("order_no");
        if (elem.value == "Lock") {
            $.ajax({
                type: 'POST',
                data: {Lock_Id: 1, Order_No: orderid},
                url: '@Url.Action("LockClick","Orders")',
                success: function (result) {
                    elem.value = "Unlock";
                }
            });
        } else if (elem.value == "Unlock") {
            $.ajax({
                type: 'POST',
                data: {Lock_Id: 0, Order_No: orderid},
                url: '@Url.Action("LockClick","Orders")',
                success: function (result) {
                    elem.value = "Lock";
                }
            });
        }
    }
</script>

Help will highly be appreciated, I might be making a mistake somewhere.

A:

First you need to convert native javascript data object to JSON. Just like that:
data:JSON.stringify({Lock_Id: 1, Order_No: parseInt(orderid)})

Also you need to specify content type of your AJAX request:
contentType: 'application/json',

Also you have following mistake in js code:
var orderid = document.getElementById("order_no")

now in orderid you have object, not value of element. I assume on orderid you just have simple html input field. In this case you need replace your string by following:
var orderid = document.getElementById("order_no").value;

Also you need to parse orderid to int, because it came from .value as string and you expect integer in your controller's method.
Thank you for posting controller's code. There are several tiny mistakes on it. Please use following string to fix:
public ActionResult LockClick(int Lock_Id, int Order_No, int cust_acctNo = 0, int store_id = 0)

Please be sure you have named method parameters exactly as they named in client side javascript - it will makes your code more strict and visual.
I have added default value for cust_acctNo parameter because you never pass it's value from client side to server side - in your example you have only pass two parameters instead of three.

Now it should work.
Please find fixed javascript code below:
<script type="text/javascript">
    function change() {

        var elem = document.getElementById("lockId");
        var orderid = document.getElementById("order_no").value;
        if (elem.value == "Lock") {
            $.ajax({
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ Lock_Id: 1, Order_No: parseInt(orderid) }),
                url: '@Url.Action("LockClick","Index")',
                success: function (result) {
                    elem.value = "Unlock";
                }
            });
        } else if (elem.value == "Unlock") {
            $.ajax({
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ Lock_Id: 0, Order_No: parseInt(orderid) }),
                url: '@Url.Action("LockClick", "Index")',
                success: function (result) {
                    elem.value = "Lock";
                }
            });
        }

        return false;

    }
</script>

