react-router transitionTo(routeNameOrPath, [params[, query]]) hide query from URL - javascript

I am firing a method :
this.transitionTo('route', {},{search: this.state.search, type: this.state.type});
which passes query params in URL http://...route?search=%param10&type=param2
Is there equivalent method that passes these parameters without printing in URL ??

Try this:
this.transitionTo("route", { search: this.state.search, type: this.state.type });

Related

VUE how to replace json variables

I have defined in data() JSON and url variable:
data() {
return {
url: '',
startsession: {
cmd: 'start',
width: 1024,
height: 800,
url: 'https://www.test.com',
token: '',
service_id: 1,
thumbnail_width: 100,
thumbnail_height: 100,
},
url is assigned to input:
<b-form-input v-model="url" />
I also have button:
<b-button
#click="sendMessage(startsession)"
>
Could you please help me, how to replace 'url' param in JSON with url variable from input, that when i click button, the 'sesstionstart' JSON will have value from input?
You can make use of methods. First, define a method with name sendMessage and then just access the variables using this and update the startsession.url with url.
methods: {
sendMessage () {
this.startsession.url = this.url
}
}
Make sure your b-form-input component has syntax like this :
https://v2.vuejs.org/v2/guide/components.html#Using-v-model-on-Components
in base, you will pass url as prop to b-form-input, and in this child component, you need emit a event to tell parent the value of url is changed. Then, just use sendMessage method like #Yash

NodeJS : Need Help To build object with some Brackets and Braces

In my project I use request lib () and i would like to use qsStringifyOptions for query parametre but it's to much complicated in my case :/
In their documentation they link qs module to use qsStringifyOptions like them
I would like to have this URL
http://127.0.0.1:80/endpoint?foo=bar[baz:3]&aaa=[{baa:X,caa:XX,daa:[{eaa:Z,faa:ZZ}]}]&data[B]=BB&data[C]=CC
but I have this URL:
http://127.0.0.1:80/endpoint?foo=bar[baz:3]&aaa=[%7B%22baa%22:%22X%22,%22caa%22:%22XX%22,%22daa%22:[%7B%22eaa%22:%22Z%22,%22faa%22:%22ZZ%22%7D]%7D]&data[B]=BB&data[C]=CC
With this solution, the 'foo' attribute and data[B] and data[C] work fine but 'aaa' attribut not at all :
{ // some standar param URI, methode ...
useQuerystring: false,
qsStringifyOptions : {encodeValuesOnly: true, encode: false, indices: false},
qs : {
foo: 'bar[baz:1]',
aaa:'[{"baa":"X","caa":"XX","daa":[{"eaa":"Z","faa":"ZZ"}]}]',
data: {B:'BB', C:'CC'}
}
}
what i'm doing wrong? i just want it not to parse the 'aaa' attribute
thank you in advance for your help and your time

How to reference Parameters passed to Partial view in a separate javascript file?

I have a Partial view in a view which take in parameters like this:
#Html.Partial("_MarkdownEditor", new { id = "editorsection" })
#Html.Partial("_MarkdownEditor", new { id = "fieldcomments" })
In the Partial view i am trying to insert a Markdown editor according to value passed in as parameters like this:
<div id="#ViewData.Eval("id")"> </div>
<script type="text/javascript">
var #ViewData.Eval("id") = new tui.Editor({
el: document.querySelector('##ViewData.Eval("id")')})
</script>
It creates a new instance of Markdown editor based on parameter passed to the partial view.
In the source code of the tui.Editor i have a Ajax call to a controller something like this..
$.ajax({
url: 'Home/Index',
type: 'POST',
dataType: 'text',
data: { capture: reader.result },
success: function (data) {
editor.importManager.eventManager.emit('command', 'AddImage', {
imageUrl: data,
altText: 'image'
});
},
Here the problem is with this line..
editor.importManager.eventManager.emit('command', 'AddImage)
Here in the place of editor i need to reference the parameters passed to Partial view..it should be like this:
editorsection.importManager.eventManager.emit('command', 'AddImage)
fieldcomments.importManager.eventManager.emit('command', 'AddImage)
It should be done dynamically i have tried something like..
{#ViewData.Eval("id")}.importManager.eventManager.emit('command', 'AddImage)
But this doesn't work like this? How can i reference the Parameters passed to Partial view in a separate javascript file??

ngResource setting const string after param

I'm trying to create a url that will query as:
http://localhost/api/:videoID/subtitles
However writing this in angularjs using ngResource transform it into a different "format":
$resource("api/videos/:id", {id: "#_id"}, {
getTracks: {method: "GET", url: "api/video/:video_id/tracks", params: {video_id: "#_id"}}
});
//results into: http://localhost/api/subtitles?videoID=:videoID
Does anyone know how to fix this exactly?
You need to change the route mask to following:
$resource("api/:id/subtitles", {id: "#id"});

Calling a controller function in javascript that will store an entry in a database using ajax (Laravel 4)

I am trying to store an entry in a database after a click using an ajax call to a route that calls a controller function in javascript (in Laravel 4).
I have a resource "artists", that is controlled by an "ArtistsController". The view where I am making the call is called "show.blade.php" in an "artists" directory (i.e. the page shows different artists: artists/1, artists/2, etc...).
I also have a table called "fanartists", where I want to store this data. Basically, when a user clicks a button on a specific artist's page, I want the relationship to be stored in this table.
Here is the relevant code:
show.blade.php:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '*****************',
status : true,
cookie : true,
oauth : true
//xfbml : true
});
$( '.opener' ).click(function() {
FB.ui({
method: 'feed',
link: 'http://crowdtest.dev:8888/artists/',
name: 'Hello',
caption: 'Hello',
description: 'Hello!'
});
request = $.ajax({
url: "/artists/fbclick",
type: "post",
data: serialised data
});
});
};
</script>
<a class="add-list-button-no-margin opener" style="color: white; font:14px / 14px 'DINMedium','Helvetica Neue',Helvetica,Arial,sans-serif;">Play my city</a>
ArtistsController:
public function fbclick($id) {
$artist = Artist::find($id);
$fanartist = new Fanartist;
$fanartist->artist_id = $artist->id; //the id of the current artist page (i.e. artists/1, id=1)
$fanartist->fan_id = Auth::user()->id;
$fanartist->save();
}
routes:
Route::get('/artists/fbclick', array('uses' => 'ArtistsController#fbclick'));
When I include the ajax request, the FB feed does not pop up. When I remove it, it does. Also, it is not storing the data in the database like I want it to.
Do you see anything wrong here? Your help is much appreciated. Thank you.
I see some slight mistakes in your script.
In your ajax request you are using post as the method, but you have defined your route as get so either change your route to post or change ajax method to get. I will go with post route so your new route is Route::post('/artists/fbclick', array('uses' => 'ArtistsController#fbclick')');
And ajax data field should be in json format, so now you ajax request will look some what like this
$.ajax({
url: "/artists/fbclick",
type: "post",
data: {field_name :'data'}
});
Finally coming to you controller function, with silght changes
public function fbclick() {
// $artist = Artist::find($id);
$id=Input::get('field_name'); //field_name is the field name from your Json data
$fanartist = new Fanartist;
$fanartist->artist_id = $id; //the id of the current artist page (i.e. artists/1, id=1)
$fanartist->fan_id = Auth::user()->id;
$fanartist->save();
}
Everything should work now

Categories

Resources