# Other Programming > AJAX >  Ajax query, Javascript and Sharepoint

## Zamuel

Hello everyone.

I am struggling with a sharepoint project containing Ajax query. I am fairly new in C#/Ajax/Sharepoint development and don't a clear understanding. 

I am working on a bug. The scenario is as following. There is a small form which is saving information or is supposed to save information. Instead I am getting an error

Sys.ArgumentUndefinedException: Value cannot be undefined. Parameter name:method

The last code line from following is causing the error 

function saveOrderSucceeded(sender, args) {

    if ($("#" + ddOrderLiftingId).val() != "") {
        try {

            var list = currentWeb.get_lists().getByTitle('Person');
            var listItem = list.getItemById($("#" + ddOrderLiftingId).val());
            currentSPContext.load(listItem, 'WorkPhone', 'CellPhone');
            currentSPContext.executeQueryAsync(Function.createDelegate(listItem, function () {
                var item = this.get_fieldValues();
                var phoneNumbers = [];

                if (item.WorkPhone != null)
                    phoneNumbers.push(item.WorkPhone);

                if (item.CellPhone != null)
                    phoneNumbers.push(item.CellPhone);

                if (phoneNumbers.length > 0)
                    $("#" + orderLiftingPhoneId).html("Phone. " + phoneNumbers.join(", "));

            }),
                Function.createDelegate(this, this.ajaxQueryFailed)); //error occurs in here. Below is    the function where this is pointing to.

................
................

function ajaxQueryFailed(sender, args) {
    alert(args.get_message());
}

I debugged this by using Firebug and it shows that 'ajaxQueryFailed', when executed is 'undefined'. I don't know how to start solving this. Help would be appreciated.

Thanks in advance.

----------


## olivthill2

Maybe, a right parenthesis is missing in:



> currentSPContext.executeQueryAsync(Function.createDelegate(listItem, function () {


N.B. Please, place your lines of code between [code] and [/code].

----------


## Zamuel

Thanks for th reply olivthill and advices.

I Believe the code has all the brackets correctly 



```
currentSPContext.executeQueryAsync(Function.createDelegate(listItem, function () { 

...

}),

Function.createDelegate(this, this.ajaxQueryFailed));
```

----------


## Zamuel

The same query is working on the same file in following code



```
function getLatestWorksite() {
    try {
        var query = camlQueryLatestWorksite.format(currentUserId);

        var list = currentWeb.get_lists().getByTitle("Work sites");
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml(query);

        var items = list.getItems(camlQuery);

        currentSPContext.load(items, 'Include(ID, Title, WorkSiteRegistry_CustomerID, WorkSiteRegistry_Address, CustomerID, CustomerName)');
        currentSPContext.executeQueryAsync(Function.createDelegate(items, this.populateLatestWorksite),
                                           Function.createDelegate(this, this.ajaxQueryFailed));
    } catch (e) {
```

But I am not able to figure out the differency that is relevant in this case.

----------

