Invalid object passed in, u0027:u0027 or u0027}u0027 expected

Assume you have created a beautiful dynamic web app, with some cool webservices to get the results from and dynamically process + place them on the client-side.

In this dynamic app of yours you must be careful while sending (POSTing) text parameters to your services with your XMLHttpRequests because if you don't, you might encounter this error. (Assuming you are using “XMLHttpRequest” for your ajax calls.)

Let's say you have created your XMLHttpRequest object and you form the parameters to be sent along as below:

var params = "{parameter_1: '" + param_1_value + "'}";
Quick Note: In case you don't know, “parameter_1” should be the name of the parameter in your web service method receiving the call.

Then you send the request to the server-side as below:

myXHR.send(params);

And BAM! You get Invalid object passed in, u0027:u0027 or u0027}u0027 expected error in the returned result.

It is probably because your “param_1_value” parameter is a text containing ( ' ), at least in my case that was the reason. All you have to do is form your parameters as below using ( ” ) instead of ( ' ):

var params = "{parameter_1: "" + param_1_value + ""}";

Now the error should be gone.

Hope this helps someone.

Good luck,
Serdar.

3 thoughts on “Invalid object passed in, u0027:u0027 or u0027}u0027 expected

Leave a Reply

Your email address will not be published. Required fields are marked *