0

my code is some thing like this , and in success result msg.d is undefined . i think it is related to formdata as value that is passed to jquery ajax . but i dont know can i resolve it .what is wrong with that ?!

  var files = event.originalEvent.dataTransfer.files;   // i get it in drop event 
  var data = new FormData();

  jQuery.each(files, function (i, file) {
    data.append('file-' + i, file);
  });

  $.ajax({
    type: "POST",
    url: parameters.Url,
    contentType: false,
    processData: false,
    data: data,
    success: function (msg) {        //my return value from webservice is just "hello"
      alert(msg.d);
    }
  });
 }
2
  • I return just a string as a sucess value ,,, just "Hello" Commented Aug 20, 2012 at 9:33
  • [WebMethod] public string HelloWorld() { return "Hello World"; } Commented Aug 20, 2012 at 9:34

4 Answers 4

1

from your above comment can understand that, You are actually returning just a string from your server side. And in your client side you are trying to alert an argument 'd' from the ajax return. This d is not at all present.

and when you alert message you are getting message [object XMLDocument]. this XML element can change to string if you specify 'dataType: "text",' in your ajax call.

So please try like this.

  $.ajax({
    type: "POST",
    url: parameters.Url,
    data: data,
    dataType: "text",
    success: function (msg) {       
      alert(msg);
    }
  });

Hope this will work fine for you.

Sign up to request clarification or add additional context in comments.

3 Comments

i get this message "<?xml version="1.0" encoding="utf-8"?> <string xmlns="tempuri.org/">Hello World</string>" actually i get my webservice value as xml format ... and now how can i get it as a simple text ,just "Hello World" ?
If you just want text then return text from the server. Answer above.
Thank you so much Andrew . it`s so useful and helpful ;)
1
[WebMethod] 
public string HelloWorld() 
{ 
   xmlDoc.LoadXml("<root><item>Hello World</item></root>");
   return xmlDoc.OuterXML;
}

1 Comment

The data type in the ajax call should also change then. I think this is just an issue of "Human error type mismatch".
0

Are you able to alert msg or msg.success?

What is your return value from the ajax page?

Make sure you have a return argument 'd' from your ajax page.

1 Comment

Yes ... alert(msg) shows me "[object XMLDocument]" as a message ... and alert(msg.d) shows me undefined ...
0
 //my return value from webservice is just "hello"

If msg == "Hello"; then what should msg.d be? If you're only passing a string as a result, I don't see how that string can have a .d property attached to it.

2 Comments

By default WebMethod returns XML
By default. But in the poster's own comment: [WebMethod] public string HelloWorld() { return "Hello World"; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.