send a URL as a variable to another URL - javascript

there is a div that i want to load a url in it with a fix url. i define a variable to add my url next to that page name. but the variable is not replace . and the url broke.
how can i send a url as a variable to another url
<script>
$(document).ready(function(){
var url = 'reservation/oneway/list.bc?bcpage=12&page=1&cat=130';
$('.load-face').load('/one-wayajax.bc?url='+url);
});
</script>
the result is :
one-wayajax.bc?url=reservation/oneway/list.bc?bcpage=12&page=1&cat=130
and removed the other objects because there is two ? repeat behind together.
i guess i have to use the second part as a variable
the true result should be this : ? &
one-wayajax.bc?url=reservation/oneway/list.bc&bcpage=12&page=1&cat=130

Related

how to pass "id" as a path variable via url from first page to second page and assign to a variable

I need to pass the id of html card (when I click on it) to second page via URL as a path variable using JavaScript.
currently, the URL is like this : www.xyz.com/page2.html?id=2
but I need to do the same function by sending the id as a path variable to second page like this
www.xyz.com/page2.html/2
and assign that id to a variable in the second page. I need to do this using JavaScript or jQuery
Please someone help me to solve this issue.
You can use jQuery to redirect the user to another page.
let's say
//cardID is the class value of the HTML card or we can use some other selector
$( ".cardID" ).on( "click", function() {
var cardID = $(this).attr('id');
window.location.replace("www.xyz.com/page2.html/"+cardID);
});
And on another page...
var url = window.location;
var urlAux = url.split('/');
var cardID = urlAux[2]

Django URL using javascript to get client end information

My problem that I am trying to resolve is that I made an Ajax-autocorrect input feature and "onclick" of a button I get the value inside that input and attempt to make the page redirect to a Django URL.
Here is the URL inside my url.py file:
url(r'^groups/add-member/(?:/(?P<pk_group>[-\w]+))?/(?:/(?P<pk_member>[-\w]+))?/$', views.add_member, name='add-member')
inside the HTML I have this script:
<script>
function add_member(id){
var input=document.getElementById("myText").value
console.log(id) //Correctly gets ID #
console.log(input) //Correctly gets the name (string) of member instance
url = "{% url 'add-member' 0 zzzz %}".replace('0', id).replace('zzzz',input);
}
</script>
And the resulting error that I get is:
Reverse for 'add-member' with arguments '(0, '')' not found. 1 pattern(s) tried:
['flexfeed/groups/add-member/(?:/(?P<pk_group>[-\\w]+))?/(?:/(?P<pk_member>[-\\w]+))?/$']
I'm having trouble understanding my error. If anyone could suggest how to fix this issue or possibly suggest a difdferent approach to this particular problem I'd really appreciate it!
The end goal is that I want my page to redirect to my update view at the correct link!
Ok, so there is a problem with the order of what's happening. When Django renders your template it processes the tags. This happens before any javascript is called.
So you are trying to call the url with 0 and zzzz as the arguments. Django tries to fetch this and because the second argument is an empty variable here it doesn't match anything.
I would fix this by calling the url with two variables that are valid, then changing them with javascript.
url = "{% url 'add-member' 0 'change-team' %}";
url = url.replace(0, id).replace('change-team', input);
You might also be able to just put quotation marks around the zzzz.

$location return path with not replaced named parameter

I need to get page ID from route parameter, so additional data can be loaded.
Route configuration looks as follows:
$routeProvider.when('/site/pages/:pageId', {/*configudarion*/})
In controller is code for getting page ID from parameters:
var pageId = $routeParams.pageId; // when location is /site/pages/9 returns "9"
On the first load I get always the correct value of page ID. Problem starts when location is changed via go forward / backward in browser (history).
Then I start getting placeholder instead of real page ID:
var pageId = $routeParams.pageId; // when location is /site/pages/9 returns ":pageId"
I tried to access pageId parameter also via $route.current.params and $location.path().
$route.current.params returns object where pageId property is ":pageId" and $location.path() returns "/site/pages/:pageId".
Why is the controller loaded, when the parameters are not replaced yet?

Modify a parameter in url with page reload using js/jquery

I have a url like result?graphType=default&product=xyzzzz&shop=11
I just want to change value of graphType, when user clicks a button.
On click of that button i store some value in a variable, and i want to replace graphType=default with graphType=my_new_value in my url without reload.
I don't understand how to split url at graphType= .
and even if I am able to split to url at graphType, how can I replace default (which can be something else as well depending on user options) with my variable
I think your solution should be like this
$(document).ready(function(){
var queries = {};
$.each(document.location.search.substr(1).split('&'), function(c,q){
var i = q.split('=');
queries[i[0].toString()] = unescape(i[1].toString()); // change escaped characters in actual format
});
// modify your parameter value and reload page using below two lines
queries['your key']='your value';
document.location.href="?"+$.param(queries); // it reload page
//OR
history.pushState({}, '', "?"+$.param(queries)); // it change url but not reload page
});

ASP.net : Refresh page with get parameter

I have a problem when I try to refresh my page with a get parameter:
I initialize a hyper link with jQuery (I use coffeescript syntax)
id= $(this).data "id2"
url = window.location.pathname+'?Shop_id='+id
add2 = '<form><button>Valider</button></form>'
My controller :
[HttpGet]
public ActionResult EditProduct(string Shop_id){ ... }
each time, the url generated in href attribute is ok, the redirection is good when I try second and third time, but after I don't know why, the url doesn't contain the get parameter like:
/Products/EditProduct?
Instead of
/Products/EditProduct?Shop_id=0844839
Thank you.
Your first line id= $(this).data "id2" is syntaxtically wrong. Lets assume if you correct it the id variable gets assigned to "id2"
Next,
var url = window.location.pathname+'?Shop_id='+id
will set url to /Products/EditProduct?Shop_id=id2 this should very well hit your action EditProduct. To cross check this you could also put a console.log(variableName) after each line to check what value is being set in your add2 variable.
Mostly likely that your first line change will help you.

Categories