I'm trying to build a custom URL and update the URL as the user selects items in my dashboard.
For example, after clicking a few items the URL could/should look like:
#/dashboard?&portfolio=GOOG&ticker1=GOOG
Currently the URL only ends in /dashboard (console.log($location.path());)
How would I update the $location.path() to add params like so? There's plenty of questions/answers and guides on getting params from the URL, but how would you update the URL in the first place?
Say if you want to add the following:
?&portfolio=GOOG&ticker1=GOOG
just organize your params in an object, like
var params = {
portfolio: GOOG,
ticker1:GOOG
}
and use,
$location.url('/dashboard ').search(params);
Hope it helps !!!
I think I'm understanding what you're saying. I believe you could use a PHP GET function to do that. A GET function in PHP will add the information you're trying to communicate to the backend to the URL, while the POST function does not.
Related
I have a page with multiple parameters in my URL. I am trying to write a function to use on the click of an element. I want it to check if parameter pthree exists. If it does, update it to a new value (not duplicate it). If it does not exist, append it to my current URL and reload the page.
I am running into an issue when I try to update the current URL.
My current URL structure:
mypage?pone=99.9999999&ptwo=-44.4444444&pthree=1&pfour=1&pfive=1
Controller snippet:
$scope.test = function (){
$location.search('pthree', 0);
}
This partially works. It updates my URL, but it adds #?pthree=0 to the end of my current URL.
The result I would like instead is:
mypage?pone=99.9999999&ptwo=-44.4444444&pthree=0&pfour=1&pfive=1
Any thoughts on what I could do to get my desired result? Thanks in advance!
Here is what worked for me. I found that I needed to set the HTML5 mode of my app. Read more about HTML5 mode here: https://docs.angularjs.org/guide/$location.
After this, I ran into another issue when calling $location.search({ pThree: '0' }. It started writing over all of my other parameters. For example, the URL structure was changing to ?pThree=0. To solve this I had to read all parameters, update pThree, and then write all back.
I hope this helps someone else.
You can do this pretty easily by just doing:
// existing url with params
// http://myurl.com/path/view/etc?param1=abc¶m2=def
// add your new param to the search() object
$location.search().param3 = 'ghi';
// set your search again with the updated search object
$location.search( $location.search() );
This will update your url like so:
// http://myurl.com/path/view/etc?param1=abc¶m2=def¶m3=ghi
I'm new to ExtJS. I'm working with ExtJS 5. I thought it would be an easy thing to find on google, but after a long search I didn't get a clear, understandable answer. I want to pass a parameter when navigating from one page to another, so I'm able to use the value of the parameter on the second page. I use the following method to navigate to that second page:
Ext.History.add('page2')
I have the parameter I want to send assigned to a var, so if it was possible to do it like below, I could do something like:
Ext.History.add('page2?parameter=' + variable);
Update:
I solved this problem by passing a cookie and retrieving it on the next page with
Ext.util.Cookies.set(cookieName, cookieValue);
and
Ext.util.Cookies.get(cookieName);
Do you mean something like this:
var itemId = record.getData()["id"];
Ext.History.add('item&id=' + itemId); // adding items
Ext.getCmp('page2').getLayout().setActiveItem(1); // go to page
You can set parameters by adding it inside a history.add(). Take a look on
Senscha Ext.History.
In ExtJS 5 the router is the right way to do this if you need back button compatibility.
Please read
http://docs.sencha.com/extjs/5.0/application_architecture/router.html
ExtJS apps are typically single page apps so when you go from "page" to "page" (actually just panel to panel), typically URL does not change.
As far as passing params when you open a new panel, you would just let your controller handle that OR set the param in the constructor of the new Panel.
Please paste some sample code and maybe I can provide a more precise answer.
-DB
Hello I have a small website where data is passed between pages over URL.
My question is can someone break into it and make it pass the same data always?
For example let say, when you click button one, page below is loaded.
example.com?clicked=5
Then at that page I take value 5 and get some more data from user through a form. Then pass all the data to a third page. In this page data is entered to a database. While I observe collected data I saw some unusual combinations of records. How can I verify this?
yes. as javascript is open on the website, everyone can hack it.
you will need to write some code on you backend to validade it.
always think that you user/costumer will try to hack you sytem.
so take precautions like, check if user is the user of the session, if he is logged, if he can do what he is trying to do. check if the record that he is trying get exists.
if u are using a stand alone site, that u made the entire code from the ashes, you will need to implement this things by yourself.
like using the standard php session, making the data validation etc.
or you can find some classes that other people have made, you can find a lot o this on google. as it is a common problem of web programing.
if u are using a backed framework that isnt from another world, probably already has one. sp, go check its documentation.
html:
<a id = 'button-one' name = '5'> Button One </a>
javascript:
window.onload = function() {
document.getElementById('button-one').onclick = function() {
changeURL(this.attributes.name.value);
};
};
function changeURL(data) {
location.hash = data;
}
I need my app execute a function when the URL looks like this
domain.com/mobile/#email_confirmed/email#address.com/otherparam
I added this route to one of my controller:
'email_confirmed/:email/:first': 'emailConfirmed'
as well as this function:
emailConfirmed: function (email, first)
But the function never gets called... However if I change go to this url :
domain.com/mobile/#email_confirmed/emailaddresscom/otherparam
then it works fine. I guess the problem comes from the at symbol and the dots in the email address. Therefore, I was wondering if there is another way of declaring the route so that it accepts email address.
Nice question,
There are a couple hoops you have to jump through to do this, firstly you need to encode or parse in your '#' symbol. Do this either by encoding to %40 OR by passing additional parameters. For example /myemail%40gmail/com/first OR /myemail/gmail/com/first, then create function(usernamedomain, tlDomain, first) OR function(username, domain, tlDomain, first) respectively. Then inside function decode the %40 OR parse together the address.
The other way I could see you solving this would include bypassing the routing system altogether. Instead of creating a link for your user to interact with create a Sencha Component that will fire an event you can listen for (list, button etc..), then inside your controller you can either use the data inside a function in that controller or call another controller function using this.getApplication().getController('SomeOtherController').handleEmail(email, first);
I have not tried it but with the last option you should not have to encode your url at all.
Again, nice question. Let me know if there are some other specifics,
Good luck, Brad
The solution I came up with is to set up the route like this:
'email_confirmed/.*': 'emailConfirmed'
And then I retrieve the params like this in emailConfirmed:
var hash = window.location.hash.split('/');
hash.shift();
// hash[0] => email
// hash[1] => first
I'm building a search using ext-js. I have an event that fires on keyup. I want to be able to change either the URL I'm searching, or the params. I've had luck with neither.
Here's my snippit of code:
Ext.get("search").on('keyup', function() {
proxy.url = '/customer/list?key=' + $('search').value;
store.load();
});
But, no love for me. The store loads, but the proxy.url is the old value. Is what I'm trying to do possible?
Thanks in advance!
You'd probably want to use the proxy.setUrl() method instead which internally updates the connection. If changing the params is sufficient, you could also try passing the params config into the load call, e.g., store.load({params: {...}});