Click here to Skip to main content
15,742,655 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I need help please.

I have wcf service, I tried to send a request using xmlhttprequest as follows:
var xhr;

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
else if (window.ActiveXObject) {
    xhr = new ActiveXObject('Microsoft.XMLHTTP');
else {
    throw new Error("Could not create XMLHttpRequest object.");
}"POST", "http://localhost/wcfService/service.svc/GetStatus", true);

xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {

xhr.setRequestHeader("content-type", "text/xml; charset=utf-8");

var postData = '{id:"E757A1EA-AE50-4A0A-8DE1-26345DDDBD0A" }';

In the response i get "Bad Request 400"

What is my mistake please?

Thank you

1 solution

Please regard this CP article: Calling WCF Services using jQuery[^]
It uses jQuery, but should be easily adaptable to use other javascript libraries as well. There are a bunch of mature cross browser compatible javascript libraries out there so my advice is not to do AJAX in the way you outlined. Use PrototypeJS or jQuery instead.

Best Regards,
Share this answer
nisha4285 7-Feb-11 10:54am    
Thank you for your response i'll try...
Espen Harlinn 7-Feb-11 15:31pm    
Good answer, jQuery makes it easier :)
nisha4285 19-Feb-11 6:28am    
Hi, it's working really nice :)
But ic case that my customer still want to work in the old way, something like:

what is the solution?

Thank you again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900