now, I want to post the values using ajax, so I'm using base, and passing the form fields as parameters.
The problem is that base does not accept special chars like '#' or '.' or '+', and this breaks the operation.
does anybody have a workaround ?
my jquery ajax code:
$('#btnSignup').click(function () {
var firstName = $("#SignupFirstName").val();
var lastName = $("#SignupLastName").val();
var email = $("#SignupEmail").val();
var password = $("#SignupPassword").val();
$.ajax({
var url = '/Base/Ajax/GetSignup/' + encodeURIComponent(firstName) + '/'
+ encodeURIComponent(lastName) + '/' +
encodeURIComponent(email) + '/' +
encodeURIComponent(password);
and in the c# code I use this to get the original string:
System.Net.WebUtility.HtmlDecode(firstName) ...
Now, when I try to run the base method directly in the browser by typing the new url into the address, it gives an error, because I think there is some url decoding made behind the scenes in umbraco (???)
Not sure if this helps, but i had a similar problem passing an email to base. I kept getting a 404 error when the email parameter was the last in the list of parameters; so my last parameter couldnt contain special characters (most probably the . in the email).
Yes, you are both right, you cannot pass an full email address to base as a parameter, so what I did was was not pass the parameters to the base function, but rather in my base function use the request object instead and convert it to json, like so:
string post = HttpContext.Current.Request.Form[0];
SignupInput si = (SignupInput)JsonConvert.DeserializeObject(post, typeof(MyType));
problematic chars for parameters of umbraco base
Hi.
I've set up a sign up form.
now, I want to post the values using ajax, so I'm using base, and passing the form fields as parameters.
The problem is that base does not accept special chars like '#' or '.' or '+', and this breaks the operation.
does anybody have a workaround ?
my jquery ajax code:
Have you tried encoding your parameters before you send them? encodeURIComponent could be useful here.
Hi stephan, and thanks for the reply.
I tried what you suggested, but still no go.
Here is the jquery code:
var firstName = $("#SignupFirstName").val();
var lastName = $("#SignupLastName").val();
var email = $("#SignupEmail").val();
var password = $("#SignupPassword").val();
var url = '/Base/Ajax/GetSignup/' + encodeURIComponent(firstName) + '/'
+ encodeURIComponent(lastName) + '/' +
encodeURIComponent(email) + '/' +
encodeURIComponent(password);
and in the c# code I use this to get the original string:
System.Net.WebUtility.HtmlDecode(firstName) ...
Now, when I try to run the base method directly in the browser by typing the new url into the address, it gives an error, because I think there is some url decoding made behind the scenes in umbraco (???)
What can I do to solve this ?
The resource cannot be found
Requested URL: /Base/Ajax/GetSignup/abc /abc/def/abc
So, does anybody have a solution ?
How is it possible to send the base function parameters without using the url for that, something like:
var firstName = $("#SignupFirstName").val(),
lastName = $("#SignupLastName").val(),
email = $("#SignupEmail").val(),
password = $("#SignupPassword").val();
$.ajax({
url:'/Ajax/GetSignup/',
type:'POST',
data:{
firstName: firstName,
lastName: lastName,
email: email,
password: password
},
success:function(result){
// TODO: process the results from the AJAX call
}
});
Not sure if this helps, but i had a similar problem passing an email to base. I kept getting a 404 error when the email parameter was the last in the list of parameters; so my last parameter couldnt contain special characters (most probably the . in the email).
/base/Services/AddSubscriber/[email protected] - didnt work
/base/Services/AddSubscriber/[email protected]/newsletter worked
Thansk,
Ashwinth
on IIS 7.5 i find /base to break when any of the parameters you pass contains a dot
.
Yes, you are both right, you cannot pass an full email address to base as a parameter, so what I did was was not pass the parameters to the base function, but rather in my base function use the request object instead and convert it to json, like so:
Ugh, this is such a small issue but still i manage to bash my head bloody every time i run into this problem.
It would be great if /base got some bugfixes really soon.
Does anyone have any good ideas? Just manually replace in both ends to some kind of special char?
Getting the request.form is not a good solution in my case since this is in a GET.
is working on a reply...