PDA

View Full Version : Ajax.request asp.net failure



Phil.Strong
5 Aug 2007, 8:53 PM
First in for most I apologize if this has been answered (i've checked the docs, the js, and the forums):

I am trying to do a simple Ajax.request and it keeps throwing the failure function instead of the success. It does make the XHR request to the server and the params are sent correctly however on callback it is calling the failure function and not he success.

Here is the code:


Ext.Ajax.request({
url: 'ajaxpro/XHRLib.Register,XHRLib.ashx?X-AjaxPro-Method=Save',
success: function ( result, request ) {
Ext.MessageBox.show({ title: 'Success', msg: 'Data return from the server: '+ result.responseText});
},
failure: function ( result, request) {
Ext.MessageBox.show({ title: 'Failed', msg: 'Successfully posted form: '+ result.responseText});
},
params: regForm.getValues(),
method: 'POST'

});

The c#:

[AjaxPro.AjaxMethod]
public JavaScriptObject Save()
{
JavaScriptArray jarr = new JavaScriptArray();
JavaScriptString jstring = new JavaScriptString("success:true");
jarr.Add(jstring);
HttpRequest req = HttpContext.Current.Request;
string name, email;
if (req["name"] != null)
name = req["name"].ToString();
if (req["email"] != null)
email = req["email"].ToString();
JavaScriptObject o = new JavaScriptObject();
o.Add("response", jarr);

return o;
}

I get a message box with: Failed: Successfully posted form: {"Message":"Failed."}

It has to be an oversight!

Phil

tryanDLS
7 Aug 2007, 5:39 PM
Set BPs in the Ajax object and step thru the code for response handling. It's possible you're returning a bad JSON string which is causing an eval to fail.

Phil.Strong
8 Aug 2007, 4:55 AM
Set BPs in the Ajax object and step thru the code for response handling. It's possible you're returning a bad JSON string which is causing an eval to fail.
I was in fact doing just that. I was using an outdated version of AjaxPro.
New one:
http://www.codeplex.com/AjaxPro/Release/ProjectReleases.aspx?ReleaseId=6179

This new version has support for ExtJs. I'm not using it yet as I am still using Ajax.request w/ a crazy url to get the job done. I'll explore the new way of connecting soon.

Phil