if(window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open('GET', 'foo.php?bar=' + baz, true);
request.send()
I know that this can be done with PHP, but I'd like to know if/how it can be done with aspx (i.e. request.open('GET', 'foo.aspx?bar=' + baz, true);
). In the example above, the AJAX call is being made in javascript from a plain old HTML page (not PHP), but it can interact with PHP.
Can the same thing be done with aspx? If so, do I need to target the code behind file or not? Say that the aspx is only there to respond to requests like this, is there something to put in the aspx file that automatically passes the GET
to the vb/cs file?
Any help would be appreciated. I'm just more accustomed to working with PHP, but my current job is primarily a VB shop, so PHP comparisons are welcomed. Thanks.
Ajax just means "Making an HTTP request from JavaScript without leaving the page".
There is nothing special about the HTTP request.
The server can generate the response in any way you like. Static files, Perl, JavaScript (via Node), PHP, ASP.NET, any way you like.
Aspx was not meant to work this way.
You will need to catch the ajax call on the Load event of the page, and then Response.Write whatever you want to return as a string. Then you have to set the Response.ContentType and then you need to end it with Response.End.
It is complicated and a bit of a hack.
Your best option is to start learning asp net mvc which will most likely work similarly to any php mvc framework.