Skip to content Skip to sidebar Skip to footer

Coldfusion Ajax: Element Is Undefined In Arguments

I'm doing some AJAX ColdFusion testing and I have an issue while sending data to ColdFusion server using AJAX. Here is the HTML code I have:

Solution 1:

The error is mainly due to following reasons:

  1. array as an object(JSON):

You are sending array as an object so the request will be made with a contentType of application/x-www-form-urlencoded by jQuery (as you have not explicitly specified it).

Hence, the object(array in the case) will be serialized into name/value pairs and will be appended in the URL so, the server will get following arguments(which was not desired):

array[name] = 'test'

array[email] = 'abc'

So, you have to serialize the data from client side and then deserialize at the server side like this:

   $.ajax({
        url: url,
        type: type,
        data: {
            method: "testCheck",
            name: test.name,
            email: test.email,
            array: JSON.stringify(test) <--- Serialize here -->
        }

        , success: function(responce){
            document.getElementById('insert').innerHTML = responce;
        }
        , error: function(xhr, textStatus, errorThrown){
            alert(errorThrown);
        }
    });

<--- Deserialize --->
<cfset local.array = deserializeJSON(arguments.array)>
  1. argument array has no default

The argument array has no default value and was not passed during the request(due to the above mentioned reason) so, it would be undefined.

Post a Comment for "Coldfusion Ajax: Element Is Undefined In Arguments"