I have an uploadify component, which sends the files back to rails application. The problem I noticed at some point is, that for some special values data passed along are altered by the flash object.
On the client side I have
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = 'M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro='
...
}
});
});
What Rails is getting:
"authenticity_token"=>"M Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro="
When there is no '+' sign in the token everything works just fine. It looks like the flash is altering the string somehow. Any idea how to escape it? I tried CGI.escape, but result is exactly the same, '+' are stripped...
You have to use encodeURIComponent() to encode special characters:
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = encodeURIComponent('M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro=')
...
}
});
});
Actual solution is, to escape the token twice. So for example "encodeURIComponent(encodeURIComponent(token)))" or #{u u token}.
Related
I am unable to parse CSRF token from html in Cypress.
I am following this link : Logging in using CSRF Token in Cypress
Trying to follow strategy #1 in the above link but I keep getting token as undefined.
This is how my html looks like:
Return html looks like this
This is how my code looks like:
cy.request({
url: returnUrlFromLoginAPI,
followRedirect: false
})
.its('body')
.then((body) => {
const $html = Cypress.$(body)
const requestVerificationToken = $html.find("input[name=__RequestVerificationToken]").val()
console.log(requestVerificationToken)
})
})
.find looks for descendants for the current elements set and my meta tag was part of this set and not a descendant. that's why you should use .filter, cause filter looks for current set and its descendants
Not sure what the "correct" way is, but I did this:
cy.get('[name=__RequestVerificationToken]').then($rvt => {
console.log($rvt.val());
}
Raw Email is
abc+2#gmail.com
For the haml file, I have javascripts like this
$('#Search_email').on('click', function(e){
var val = encodeURIComponent($('#search_email').val());
window.location.search = 'email='+val;
});
In the query url, it shows correctly as
url?email=abc%2B2%40gmail.com
However, for the controller, when I use the debugger to monitor, it shows only
params[:email] = "abc 2#gmail.com"
Does anyone know what happens, why rails decodes directly and in a wrong way. Thanks.
I'm hitting an API that return a list of URLs, so I'm looking to iterate through them, generate links, and let the user browse to those links. I think I'm supposed to use forge.tabs.open to create a Modal view when the user taps a link. Here's the code:
$("#feed").append('<p>'+item.data.title+'</p>');
And the viewLink function:
var viewLink = function(linkurl, linktitle) {
forge.logging.log(linkurl);
forge.logging.log(linktitle);
forge.tabs.openWithOptions({
url: linkurl,
title: linktitle,
buttonText: "close"
});
};
It doesn't work on iOS and doesn't generate an error. When I run it in my browser, I get this error:
Uncaught SyntaxError: Unexpected token :
Any ideas what I'm doing wrong?
The trigger.io code you posted looks fine to me. When I see the "unexpected token" syntax error I immediately think: single quote, double quote, or character encoding.
Do any of the linktitle's have a "weird" character? Maybe you need to escape or encodeURIComponent or decodeURIComponent it?
this may or may not be possible (and could well be in the docs but i've just missed it).
How do i structure a Url.Action() inside my view using T4MVC that will allow me to use jQuery selectors. I've been attempting the following (in my javascript) without success:
function cancelHoldBooking() {
var url = '<%= Url.Action(MVC.FundProperty.CancelLock($("#propertyid").val())) %>';
// other code omitted for brevity
}
i am able to successfully do the following:
function cancelHoldBooking() {
var url = '<%= Url.Action("CancelLock", "FundProperty") %>';
url += "?id=" + $("#propertyid").val();
// other code omitted for brevity - in this case
// **I could of course have used the**:
// var params = {id: $('#propertyid').val()};
// **object**
}
i know this will be a 'doh' moment when the answer arrives, but for the life of me, I can't figure this out!!
cheers...
[edit] - i would just add that if i omit the MVC.FundProperty.CancelLock() id paramater and attempt to just send the params object via the $ajax call, then the compiler complains about the missing parameter in the call. i can't therefore by-pass the javascript mish-mash by calling using the $ajax params object with no parameters inside the CancelLock() call. frustrating :(
I think you're trying to mix client and server code in a way that just can't work. :) The <%= ... %> block is pure server side code, so it can't be using a JQuery selector. The best you can do with T4MVC might be something like:
function cancelHoldBooking() {
var url = '<%= Url.Action(MVC.FundProperty.CancelLock()) %>';
url += "?id=" + $("#propertyid").val();
}
It still saves you from literal strings for the action and controller name, but won't help you with the param.
You have to realize that <%= ... %> is processed on the server while $("#propertyid").val() is run on the client when the function cancelHoldBooking is called.
One way to solve your problem is this:
function cancelHoldBooking() {
var url = '<%= Url.Action(MVC.FundProperty.CancelLock(999)) %>'; // Provide a magic number
url += url.replace('999', $("#propertyid").val()); // Replace the magic number
// other code omitted for brevity - in this case i could
// of course have used the params {id: $('#propertyid').val()} object
}
I have a form. I am trying to validate it through AJAX GET requests.
So i am trying to send the field values in the GET request data.
$('#uxMyForm').serialize();
the problem it is returning something undecipherable. I have used serialize before. This is totally bizzare.
the return value of serialize is
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&customer%5BuxName%5D=&customer%5BuxEmail%5D=&customer%5BuxResidentialPhone%5D=&customer%5BuxMobilePhone%5D=&customer%5BuxDateOfBirth%5D=&customer%5BuxAddress%5D=&customer%5BuxResidentialStatus%5D=
i have no idea how to use this.
Thanks
update:
My question is how do i process such a request? like this?
puts params[:data][:customer][:uxName]
my GET request trigger looks like this
$.get('/site/sign_up',{data : $('#uxMyForm').serialize() }, function(data){
alert(data);
});
The above jquery lines generate the request.. on the action method i do the following
render :text => params
when i observe what is sent in the GET,in firebug PARAMS
**data** authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
the return value that i print in alert has
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
How does the form itself look. I have no experience with Ruby on rails - and if it builds the form in a new exciting way - but it looks as if there's only two form elements: authenticity_token and customer - where customer is an array of items. This is the data you posted, but I urldecoded it and put in some linebreaks:
authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6/Q0zLeQqwIahJZJfE=
&customer[uxName]=
&customer[uxEmail]=
&customer[uxResidentialPhone]=
&customer[uxMobilePhone]=
&customer[uxDateOfBirth]=
&customer[uxAddress]=
&customer[uxResidentialStatus]=
What you could do is to serialize the form to an array and clean it up before sending it using jQuery ajax request. I did something similar once when I had to serialize .net runat-server form elements:
var serializedData = $(form).serializeArray();
for( i=0; i < serializedData.length; i++)
{
// For each item in the array I get the input-field name after the last $ character
var name = serializedData[i].name;
var value = serializedData[i].value;
if( name.indexOf('$') != -1)
name = name.substr( name.lastIndexOf('$')+1 );
serializedData[i].name = name;
}
var ajaxPostData = $.param(serializedData);
So instad of blabla$ABCPlaceHolder$tbxEmail I got tbxEmail in the array. You could do the same to get uxName, uxEmail etc instead of the customer array.
Note then again, however, due to my inexperience with ruby that this may not be the best solution - maybe there's a setting you can change to build the HTML form differently?
Updated:
I'm not sure how ruby works, but after a googling I found you should be able to receive your values using params:customer as an array.
params:customer should contain an array of the values
{:uxName => "", :uxEmail => "" }
I hope that tells you something on how to receive the data. Maybe (warning - wild guess!) like this?
params[:customer][:uxName]