peyman gilmour
peyman gilmour

Reputation: 1218

Undefined result in ajax jquery

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);
    }
  });
 }

Upvotes: 0

Views: 1043

Answers (4)

Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

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.

Upvotes: 1

user554180
user554180

Reputation:

[WebMethod] 
public string HelloWorld() 
{ 
   xmlDoc.LoadXml("<root><item>Hello World</item></root>");
   return xmlDoc.OuterXML;
}

Upvotes: 1

Flater
Flater

Reputation: 13763

 //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.

Upvotes: 0

Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

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.

Upvotes: 0

Related Questions