0

In PHP, I can call a page like this

var data = {
    type: 'simple_data'

};

jQuery.ajax({
    url: 'http://www.example.com/haha.php',  //load data 

    type: "POST",
    dataType: "xml",
    data: data,
    async: false,
    success: loading_complete,
    error: function (request, status, error) {
        alert(error);
    }
});

And in the PHP server side page, we catch it like

$type=$_POST['type'];

Pretty simple right! It gives back the XML info and GOAL.

Now I want to do it for ASP.NET pages in same way as PHP. I want to call the ASP.NET page like

var data = {
    type: 'simple_data'

};

jQuery.ajax({
    url: 'http://www.example.com/haha.aspx',  //load data 

    type: "POST",
    dataType: "xml",
    data: data,
    async: false,
    success: loading_complete,
    error: function (request, status, error) {
        alert(error);
    }
});

So how can I catch the data and extract values in ASP.NET. That means I want the functionality similar to this '$_POST['type']' in ASP.NET. I tried to search but nothing found yet or may be didn't find in the right direction. Can anyone please tell me how can I extract this data from this ajax call with XML??

2 Answers 2

1

You can use Request.Form["type"]

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

1 Comment

Great. Small, Sweet and simple. Thank you so much :)
0

It is very easy. You need to pass the method name in your URL parameter like so:

jQuery.ajax({
    url: 'http://www.example.com/haha.aspx/MethodName',  //load data 
    type: "POST",
    dataType: "xml",
    data: data,
    async: false,
    success: loading_complete,
    error: function (request, status, error) {
        alert(error);
    }
});

ASP.Net will know how to handle the web request and parse the data. You can write something on the .aspx page as simple as:

[WebMethod]
public static string MethodName(string type)
{
    // do work with type
}

1 Comment

Is it necessary to keep the MethodName function Static?? I can't make my own method static due to some other dependencies. And this technique is not working for me though it looks good. The AJAX call isn't working with the MethodName.

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.