First of all i wanna say sorry for that if my question is silly question,Iam confused with this because im new in Angular.
Before asking question i want to introduce about my code,
this is the get functon that exactly i have called api,
get(feepaid_report: FeepaidReport): Observable<FeepaidReport[]> {
const options = this._utils.makeOptions(this._headers);
return this._http.get(`${this._feepaidreportUrl}`, options).pipe(
map((res: Response) => res.json()),
tap(
data => this.afterGetRequest(),
error => { console.log(error); }
));
}
Here in this code _feepaidreportUrl is my baseUrl that looks like this:
private _feepaidreportUrl = `${new Config().api}/report/feepaid_report/`;
And the my argument feepaid_report of type FeepaidReport is comes with data of dictionary like this,
FeepaidReport: {paid_date: "2019-01-03", classes: "class12"}
And i want to append this dictionary (i.e feepaidreport data) in url so that i can pass the url for backend like that:
baseurl/?paid_date=2019-01-03&classes=class12
Hope you will understand my question
Above problem is solved by doing this:
get(feepaid_report: FeepaidReport): Observable<FeepaidReport[]> {
var url = `${this._feepaidreportUrl}/?`
for(var key in feepaid_report){
var val = feepaid_report[key];
if (typeof(val) !=='undefined'){
url = url + key + '=' + val + '&'
}
}
const options = this._utils.makeOptions(this._headers);
return this._http.get(url, options).pipe(
map((res: Response) => res.json()),
tap(
data => this.afterGetRequest(),
error => { console.log(error); }
));
}
Related
In new Zapier UI, I used to do below..
return z.request(options).then(response => {
response.throwForStatus();
const results = z.JSON.parse(response.content);
let attachmentArray = [];
attachmentArray = results.data.map(function(result) {
let attachment = {};
attachment.id = result.attachment_id;
let file_url = options.url + `/${attachment.id}`;
attachment.url = file_url;
attachment.file = z.dehydrateFile(file_url, {
method: "GET",
headers: { Authorization: `Bearer ${bundle.authData.access_token}` }
});
return attachment;
});
return attachmentArray;
});
This is my code to provide a trigger. Currently, it throws
Error: You must pass in a function/array/object. We got string instead.
David here, from the Zapier Platform team. That error comes from this line, which is responsible for finding methods on your root App object. We've actually got a test covering that exact case here.
The offending code doesn't seem to be in the sample you provided above, but take a look at anywhere you're calling dehydrate('some str') or appTester('some string')
I tried to change the existing angularjs library to angular2 for my need. http.post method in the below code throws TypeError {} as exception. Someone please help as i am stuck on this.
login() {
return new Promise((resolve, reject) => {
if(typeof jsSHA !== "undefined") {
var signatureObj = (new OauthUtility()).createSignature("POST", this.magentoOptions.baseUrl+"/oauth/initiate", this.oauthObject, {oauth_callback: "http://localhost/callback"}, this.magentoOptions.clientSecret, null);
let headersInitiate = new Headers();
headersInitiate.append('Authorization',signatureObj.authorization_header);
headersInitiate.append('Content-Type','application/x-www-form-urlencoded');
let url = this.magentoOptions.baseUrl + "/oauth/initiate";
let callback = "oauth_callback=http://localhost/callback";
try{
this.http.post(url, callback,{headers: headersInitiate})
.subscribe(
(result) => {
console.log("i am inside");
var rParameters = (result).split("&");
.....
}
catch(Exception){
console.log(Exception)
}
You should try something like that:
var signatureObj = (new OauthUtility()).createSignature("POST",
this.magentoOptions.baseUrl+"/oauth/initiate", this.oauthObject,
{oauth_callback: "http://localhost/callback"},
this.magentoOptions.clientSecret, null); let headersInitiate = new Headers();
headersInitiate.append('Authorization',
signatureObj.authorization_header);
headersInitiate.append('Content-Type',
'application/x-www-form-urlencoded');
let url = this.magentoOptions.baseUrl + "/oauth/initiate";
let payload = ' ... ';
this.http.post(url, payload,{headers: headersInitiate})
.subscribe(
(result) => {
console.log("i am inside");
var rParameters = (result).split("&");
(...)
});
Here are the comments I would have on your code:
The second parameter of the post method should be a string corresponding to the payload not a callback. I see from your headers that you want to send url-encoded form, so you need to create it by your own
The try catch isn't necessary since executing an HTTP is asynchronous and errors can be "catched" within the second parameter (another callback) of the subscribe method.
You don't need at all a promise. For HTTP, Angular2 uses observables under the hood. They target asynchronous processing as well.
After fixing all of this, I think that you won't have error anymore...
Hope it helps you,
Thierry
I found to stuck even after proceeding with the above all steps. The complete solution is as follows.
Remove try catch block and promise as suggested by Thierry.
Use dependency injection of http inside the constructor as follows to define http.
import {Http,HTTP_PROVIDERS,Headers} from 'angular2/http';
import {Injector} from "angular2/core";
constructor() {
var injector = Injector.resolveAndCreate([HTTP_PROVIDERS]);
this.http = injector.get(Http);
}
It seems quite simple but there is something I am not able to figure out. I hope someone can help me fast.
I have an url, something like http://host/controller/action/argument/named:1/?query1=1. I want to add another query param to look it like http://host/controller/action/argument1/argument2/named:1/?query1=1&query2=2. I fact I want to add query2=2 to all URLs on a particular page, through some callback or something.
An URL may or may not have query params in the existing page URL.
How do I do it?
Example url : http://www.example.com/myController/myAction/param1:val1/param2:val2
You can use :
$this->redirect(array("controller" => "myController",
"action" => "myAction",
"param1" => "val1",
"param2" => "val2",
$data_can_be_passed_here),
$status,
$exit);
Hope it helps you.
May be I am thinking too much of it but here is how it came out. I put it in a UtilityHelper.
function urlmodify($params = array(), $baseurl = true) {
$top_level_1 = array('plugin', 'controller', 'action'); //top level vars
$top_level_2 = array('pass', 'named'); //top level vars
//for integrated use
$top_level = array_merge($top_level_1, $top_level_2);
$urlparams = array();
//get top level vars
foreach($top_level as $k) {
if(in_array($k, $top_level_1)) {
$urlparams[$k] = $this->request->params[$k];
}
if(in_array($k, $top_level_2)) {
$$k = $this->request->params[$k]; //create $pass & $named
}
}
//get query vars
if($this->request->query) {
$urlparams['?'] = $this->request->query;
}
//check for custom pass vars
if(isset($params['pass'])) {
$pass = array_merge($pass, $params['pass']);
}
//pass var has to be in numarical index
foreach($pass as $v) {
array_push($urlparams, $v);
}
//check for custom named vars
if(isset($params['named'])) {
$named = array_merge($named, $params['named']);
}
//pass var has to be in key=>value pair
foreach($named as $k=>$v) {
$urlparams[$k] = $v;
}
//check for custom query vars
if(isset($params['?'])) {
$urlparams['?'] = array_merge($urlparams['?'], $params['?']);
}
return Router::url($urlparams, $baseurl);
}
}
I have an URL: http://localhost/project/exlplugin/logs/manage_columns/1/a:1/n:1/?b=1. On some links I want to add some certain parameters. Here is the result when i call
echo $this->Utility->urlmodify(array('pass'=>array(2), 'named'=>array('m'=>2), '?'=>array('c'=>2)));*
It gives: http://localhost/thecontrolist/spreadsheet/logs/manage_columns/1/2/a:1/n:1/m:2?b=1&c=2
I just wanted to add just a query parameter to all my listing urls deleted=0 or deleted=1 for the SoftDelete thing :)
Thank you #u2460470 for the answer but it's just about modifying (not removing or creating anything but just adding some params to) current URL on a view page.
I have problem with autocomplete. The code below is returnig me
["foo#foo.com","bar#bar.com"]
$('.autocomplete').keyup(function() {
tid = $(this).attr('id')
$(this).autocomplete({
source: function (req, resp){
$.ajax(
{
url: "autocompl.asp",
data:$("#msgForm").serialize() + "&field="+tid ,
success : function( resp ) {
return resp
}
})
}
});
});
But the suggestions don't appear. It worked for me when I have called autocomplete without any extra parameters.
Any clue?
Thanks in advance
Magda
Note that one of your parameters for the source function is resp, and you're using another resp afterwards. I think you need to use the first resp to send the response object back.
I'm using this as well and this works for me (Instead of sending an array of values, I'm sending an array of objects with two attributes, but I don't think it's mandatory).
id
label
so the code inside the ajax success should look something like this (my data variable is your second resp variable, a different name to avoid mixup):
success: function(data) {
for (i in data) {
a = {}
a.id = data[i]
a.label = data[i]
options.push(a)
}
resp(options)
}
I'm currently developing a Firefox add-on(using https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/ ) that consumes an API where the return data is in xml.
My problem is that I need to parse the returned data, and would like to do that using a xml object.
Since the request module only supports JSON and Text ( https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/request.html#Response ) I need to convert the response.text to XML.
The code looks like this:
var Request = require('request').Request
.......
var req = Request({
url: https://to-the-api.com,
content: {
op: 'get-the-data-op',
password: "super-sec",
user: "username"
},
onComplete: function (response) {
dataAsText = response.text;
console.log("output: " + dataAsText);
}
});
req.post();
I have tried to user (new DOMParser).parseFromString(response.text, 'text/xml') but unfortunately it just fails with a error like ReferenceError: DOMParser is not defined
The question is if anyone of you guys have been able to create a Xml object inside a Firefox add-on, and if so, how?
Looks like the capability to parse response as xml was present, but has been removed. check out this bugzilla reference
Can't you use a normal XMLHttpRequest if you want to process the response as XML?
If DOMParser is unavailable you can try E4X:
var xml = new XML(response.text);
alert(xml.children().length());
You want to use the XMLHttpRequest object to handle your xhr request. Then when you get a response back access the responseXML object of the request variable. In the responseXML you'll have the documentElement and can use the querySelectorAll or querySelector to find elements you want. In each element you want just grab the textContent you need.
Here's an example to get you going (this looks for the 'xmls' element in the response):
var request = new require("xhr").XMLHttpRequest();
request.open('GET', 'https://to-the-api.com', true);
request.onreadystatechange = function (aEvt) {
if (request.readyState == 4) {
if(request.status == 200) {
var xmls = request.responseXML.documentElement.querySelectorAll("xmls");
for (var i = 0; i < xmls.length; i++) {
console.log("xml", i, xmls[i], xmls[i].textContent);
}
}
else {
console.log('Error', request.responseText);
}
}
};
request.send(null);