0

How can i make a asmx web method that can accept a content type "application/x-www-form-urlencoded".

Please see below code:

// create request object
var req = createRequest();
var params = "core_lesson=English&core_grade=80&core_average=90";

// set up request parameters - uses POST method
req.open('POST','commit.asmx/commit',false);

// request headers
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");

// submit to the server for processing
req.send(params);

function createRequest() {
  var request;
  try {
    request = new XMLHttpRequest();
  }
  catch (tryIE) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (tryOlderIE) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (failed) {
        alert("Error creating XMLHttpRequest");
      }
    }
  }
  return request;
}

The above code is an example of "application/x-www-form-urlencoded" content type request. I need to know how to make an asmx method to accept those request.

Furthermore, I need to upgrade also that old ajax and replace it using ajax in jquery. Please advise also how to do it.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
jeff
  • 448
  • 1
  • 15
  • 34
  • Your "furthermore" should be a separate question. Also, were you aware that ASMX is a legacy technology and should not be used for new development? – John Saunders Jan 22 '12 at 18:10
  • possible duplicate of [Enable ASP.NET ASMX web service for HTTP POST / GET requests](http://stackoverflow.com/questions/618900/enable-asp-net-asmx-web-service-for-http-post-get-requests) – John Saunders Jan 22 '12 at 18:10

0 Answers0