2

I'm trying to get familiar with ASP .net so after 'hello world' I was trying to add some simple backend request handling. So I'm doing an Ajax request from my page to the asp page :

    Ext.Ajax.request({
        type: 'POST',
        url: 'http://http://localhost:49852/Default.aspx',
        params: {
            html        : {'array': document.body.innerHTML}
        },
        success : function(response){
        console.log('RESPONSE !', response);
            //me.onSuccess(response, callback, errback);
        },
        failure : function(response){
            console.log('RESPONSE FAIL !', response);
        }
    });

And this is my page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

And the code that's behind it (I'm not sure if the structure should look like this, but I wasn't able to find any example of requests handling without forms used) :

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page{
    protected void Page_Load(object sender, EventArgs e){
        if (this.Request["html"] != null){
            this.Response.Write("{'success': true, 'msg': 'Its working'}");
       }
        else{
            this.Response.Write("{'success': false, 'msg': 'Error in request data.'}");
        }
    }
}

Now if I go to this address in my browser, I'm getting the proper (false) text displayed. But when I'm trying with XHR request, I can't see any request in the Firebug console at all, and in the Net tab I get 'OPTIONS' response :

enter image description here

which looks as follows when logged to console :

enter image description here

Any ideas what's goin on here ?

mike_hornbeck
  • 1,612
  • 3
  • 30
  • 51

2 Answers2

2

Your URL is wrong. It is:

http://http://localhost:49852/Default.aspx

When it should be:

http://localhost:49852/Default.aspx
lontivero
  • 5,235
  • 5
  • 25
  • 42
1

Try using a WebService marked with SciptService instead of a Page.

Here's an example from MSDN:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class SimpleWebService : System.Web.Services.WebService 
{
    [WebMethod]
    [ScriptMethod]
    public string GetServerTime() 
    {
        string serverTime =
            String.Format("The current time is {0}.", DateTime.Now);

        return serverTime;
    }
}
jrummell
  • 42,637
  • 17
  • 112
  • 171