I need a help for How to get Individual values from HTML page.
i got response from some PAYU payment gateway team in HTML page but i need individual attributes values from tacking Transaction
Below is the response am getting from PAYU Team:
<h1>This is the success url</h1>
<p>Your transaction is completed successfully. Bank response is
mihpayid=403993715514374636&mode=&status=failure&unmappedstatus=userCancelled&key=gtKFFx&txnid=txn1r23fw&amount=100.00&discount=0.00&net_amount_debit=0.00&addedon=2016-04-25+10%3A48%3A29&productinfo=oxygenconcentrator&firstname=test&lastname=&address1=&address2=&city=&state=&country=&zipcode=&email=test%40gmail.com&phone=8152709721&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=6a9d21bd423d61cd5a7d91098aa1140314e45eaddd8d4b9148399caba8ac61a9476aec130eb369f7d526e741b1b6c47b1ca71bec21fa69aa3deaa13740dbffbc&field1=&field2=&field3=&field4=&field5=&field6=&field7=&field8=&field9=Cancelled+by+user&payment_source=payu&PG_TYPE=&bank_ref_num=&bankcode=&error=&error_Message=
</p>
<script>
PayU.onSuccess("mihpayid=403993715514374636&mode=&status=failure&unmappedstatus=userCancelled&key=gtKFFx&txnid=txn1r23fw&amount=100.00&discount=0.00&net_amount_debit=0.00&addedon=2016-04-25+10%3A48%3A29&productinfo=oxygenconcentrator&firstname=test&lastname=&address1=&address2=&city=&state=&country=&zipcode=&email=test%40gmail.com&phone=8152709721&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=6a9d21bd423d61cd5a7d91098aa1140314e45eaddd8d4b9148399caba8ac61a9476aec130eb369f7d526e741b1b6c47b1ca71bec21fa69aa3deaa13740dbffbc&field1=&field2=&field3=&field4=&field5=&field6=&field7=&field8=&field9=Cancelled+by+user&payment_source=payu&PG_TYPE=&bank_ref_num=&bankcode=&error=&error_Message=");
</script>
I got this response from below snippet
iabRef.executeScript(
{ code: "document.body.innerHTML" },
function( values ) {
alert(values[0]);
console.log(values[0]);
}
);
so i need individual attribute values like mihpayid ,mode,status and so on......
Assuming that values or values[0] will have :
"mihpayid=403993715514374636&mode=&status=failure&unmappedstat"
Then you could write a function as below:
function extractScript(source){
var pattern = /<script>(\w+)<\/script>/
var matches = source.match(pattern);
return matches[1];
}
function getValue(source, key){
var pattern = key+'=(\\w+)(&)?';
var expr = new RegExp(pattern);
var result = source.match(expr);
return result[1];
}
Then in executeScript:
iabRef.executeScript(
{ code: "document.body.innerHTML" },
function( values ) {
//incase values[0] contains result string
console.log(getValue(values[0], 'mihpayid'))
//or
//incase values[0] contains result string
console.log(getValue(values, 'mihpayid'))
}
);
You can just get the contents of the p tag then perform a split twice
Assuming that p is the only p tag in the page you can get the value by calling
var text= document.getElementByTagName('p').innerHtml;
First split the &
var theArray= text.split('&');//or just & depending on how your text comes out
this will return an array that'll contain something like [status=failure,phone=8152709721]
Then you can loop through this array and create an object
var obj = {} ;
//loop here then do this within the loop
var kv=theArray[i].split('=');
obj[kv[0]] = kv[1];
So you can get your attributes by calling obj.status
Related
I am trying to retrieve the value attribute of an unsubmitted input field as parameter to a URL that opens/saves an excel file. The Parameters are supposed to be used to filter the excel file.
I have tried using a for()-loop to save the parameters into an array and then proceed to use the append() method to add them to the end of the url.
Code below shows how I am trying to singularly append each parameter one after the other
var url = new URL("file:database/reports/getCurrentStorageOverview.php?params=excel");
var query_string = url.search;
var search_params = new URLSearchParams(query_string);
search_params.append('params', $("#searchParameter1").val());
search_params.append('params', $("#searchParameter2").val());
search_params.append('params', $("#searchParameter3").val());
search_params.append('params', $("#searchParameter4").val());
url.search = search_params.toString();
var new_url = url.toString();
window.open("database/reports/getCurrentStorageOverview.php?params=excel");
console.log(new_url);
The parameters are supposed to be added to the end of the url however the console keeps telling me the value attribute is either undefined/ when i was trying to use an array it was filling the array with 4 "undefined(s)"
it's a different aproach but since i haven't tested your method i can show u what i normally use for this case:
const querify = obj => {
return Object.keys(obj)
.map(key => {
if (typeof obj[key] === 'object') {
return querify(obj[key])
} else {
return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`
}
})
.join('&') }
what this does is it takes an object like
var filters = { page: 1, length: 10, sortBy: 'id', etc... }
and turns it into a query string that looks like "page=1&length=10&sortBy=id" etc so u can use it like this:
var url = `database/reports/getCurrentStorageOverview.php?${querify(filters)}`
i need to print an array of json object which are been entered by user through text box, this function is executed by button click. i need to store all the string localy that are entered by the user in text box. and display it in my console in this formate [{"aaa"},{"bbb"},{"ccc"}]
<!DOCTYPE html>
<html>
<body>
Enter the string :
<input type="text" id="names">
<button onclick="myFunction()"> Click Me</button>
<script>
function myFunction(){
var myNames = new Array();
myNames = document.getElementById("names").value;
this.names = myNames;
localStorage["myNames"] = JSON.stringify(myNames);
console.log(JSON.stringify(myNames));
var name = JSON.parse(localStorage["myNames"]);
console.log(name);
};
</script>
</body>
</html>
Currently this code just print the data like this "aaa", if i add another data bbb, only the 2nd data "bbb"is displayed. i want all the data to be viewed in this formate [{"aaa"},{"bbb"},{"ccc"}] or even like this [{"name":"aaa"},{"name":"bbb"},{"name":"ccc"}] .
Could someone help me?
That's not related to localStorage or JSON.
When you perform myNames = document.getElementById("names").value; you replace the empty Array with a string.
You may use .push on array : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push
And create an object then pushing it, for example myObj = {'v': value}; myArray.push(myObj);
you can try this:
var myNames = []
function myFunction(){
var oldItems = JSON.parse(localStorage.getItem('myNames')) || [];
newItem = {"name":document.getElementById("names").value};
oldItems.push(newItem);
localStorage.setItem("myNames", JSON.stringify(oldItems));
console.log(JSON.parse(localStorage.getItem("myNames")));
};
If you want to preserve the previously entered data, you have to retrieve them first and alter them.
Below are two functions; one that adds an item to the array. If the array isn't present yet (so no data has been entered previously), it creates a new array for you.
Afterwards it stores the data in the localStorage again.
Upon entering new data that needs to be added, it first retrieves any previous entries and alters that. Then it stores again and so on and so on.
function myFunction(){
var myNames = localStorage.getItem('myNames'),
parsedArray = JSON.parse(myNames),
valueToAdd = document.getElementById("names").value;
// Add the new item to the original array.
parsedArray = addToArray(parsedArray, valueToAdd);
localStorage.setItem('myNames', JSON.stringify(parsedArray));
console.log(parsedArray);
};
function addToArray (array, item) {
// If the array doesn't exist, create one
if (!array) {
array = [];
}
// Add the item to the array.
array.push(item);
return array;
};
I am creating a "Garment checker" using ajax and I would like the user to put the ID into the input followed by a request to the URL. which prints out the code if it exists. The code below just isn't doing the job as I would like it to although I think that it is almost correct. Can anybody see my mistakes or point me in the right direction please?
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
"use strict";
$('#lookupForm')
.removeAttr('onsubmit')
.submit(function(event) {
event.preventDefault();
var target = document.getElementById('garmentID');
if(target.value.length > 0) {
fetchData(target.value);
}
});
});
function fetchData(garmentID) {
var url = 'http://staging.me-tail.net/api/3.0/retailer/4/garmentsAvailable?guid=' + applicationID;
$.getJSON(url, function(data) {
var appDetails = data.AvailableSkus[0];
$('#garmentTitle').val(appDetails.AvailableSkus);
});
}
//]]>
</script>
Since data.AvailableSkus seems to be an array, you don't want to pass the collection as the value to #garmentTitle.
You're most likely after a property (if the array contains objects) or the actual element:
//if typeof appDetails.AvailableSkus[0] is string or number:
$('#garmentTitle').val(appDetails.AvailableSkus[0]);
or
//if typeof appDetails.AvailableSkus[0] is an object:
$('#garmentTitle').val(appDetails.AvailableSkus[0].someProp);
value
Type: String or Array
A string of text or an array of strings corresponding to the value of each matched element to set as selected/checked.
This link provides output properly
http://staging.me-tail.net/api/3.0/retailer/4/garmentsAvailable?guid=5
are you sure "applicationID" is setted before ?
var url = 'http://staging.me-tail.net/api/3.0/retailer/4/garmentsAvailable?guid=' + applicationID;
Any error message in firebug console ?
I'm attempting to return a json object in my typeahead rather than just a single query. The idea is to pass along additional fields in my autocomplete menus to help filter down the results. Example year, make, model, trim. the json object would contain the filteredBy field id and field value. Example when searching make, the json object will contain the filter field id "year" and value"2013" plus the current field id and it's value.
Currently this works below, but only returns a single value.
return $field.typeahead({
replace: (uri, query) {
return extendURL(uri, "t:input": query);
}
}
This is how I'm trying to do it.
<input id="year" value="2013"/>
<input id="make" filterBy="year" value="ford"/>
<input id="model" filterBy="ford" value="fusion"/>
init = function(spec) {
var $field = $("#" + spec.id),
filterIdArray = [];
if (typeof spec.filterId !== 'undefined') {
filterIdArray = spec.filterId.split(',');
}
return $field.typeahead({
replace: function(uri, query) {
var params = {};
params["t:jsonStringField"] = searchField(spec.id, query);
params["t:jsonStringFilter"] = searchFilter(filterIdArray);
var stringify = JSON.stringify(params);
//I'm trying to pass back this stringified json object.
return extendURL(uri, stringify);
}
}
//The current search input
searchField = function(fieldId, query) {
return {name: fieldId, value: query};
};
//Additional fields used to create where clause within searchField
searchFilter = function(filterIdArray) {
var array = [];
//Field Id's and any fields being filtered by
for (var i = 0; i < filterIdArray.length; i++) {
var value = $("#" + filterIdArray[i]).val(),
name = filterIdArray[i];
array.push({name: name, value: value});
};
return array;
};
I end up getting the following error.
"NetworkError: 500 Internal Server Error - /TapDemo/sell/createlisting.year:autocomplete?category=aircraft&0={&1=%22&2=t&3=:&4=j&5=s&6=o&7=n&8=S&9=t&10=r&11=i&12=n&13=g&14=F&15=i&16=e&17=l&18=d&19=%22&20=:&21={&22=%22&23=n&24=a&25=m&26=e&27=%22&28=:&29=%22&30=y&31=e&32=a&33=r&34=%22&35=,&36=%22&37=v&38=a&39=l&40=u&41=e&42=%22&43=:&44=%22&45=5&46=%22&47=}&48=,&49=%22&50=j&51=s&52=o&53=n&54=S&55=t&56=r&57=i&58=n&59=g&60=F&61=i&62=l&63=t&64=e&65=r&66=%22&67=:&68=[&69=]&70=}"
Does anybody know what I'm doing wrong?
What you need to do is, send these values as json encode and make sure you decode the data as an array, in that way you be able to handle these values.
Hey friends i am using javascript sdk to post on users friends wall with jQuery facebook multi friend selector however i am getting this error friendId.split is not a function. Here is my code
function recommendToFriend(pic, url, friendId, fromName)
{
alert(friendId);
var friendList ;
pFriend = new Array();
pFriend = friendId.split(',');
for( x in pFriend )
{
alert(pFriend[x]);
var publish = {
method:'feed',
picture:pic,
link:url,
name:'SHARP Product Recommend',
caption: fromName + 'has recommend a product to you via Sharp Expert lounge',
};
FB.api('/'+pFriend[x]+'/feed', 'post', publish, function(resp) {
if( !response || response.error )
alert('Unable to share');
else
alert('Successfully posted to firends wall');
});
}
}
In alert box i got comma seperated friend ids so i use split function post on each users wall seperately i dont know whats wrong here please help me
Most probably friendID is already an array. If you call alert the array is converted to a string and becomes a comma separated list of values.
Note that converting an array to a string is not the same as calling JSON.stringify (where you get also brackets and double quotes around elements when they're strings)
The JavaScript split() function is for the type string ie for eg.
var friendid='1,34,67';
As VisioN says, when you alert an array you get comma separated values.
You can traverse JS Objects like this
for (var key in friendid) {
var obj = friendid[key];
for (var prop in obj) {
alert(prop + " = " + obj[prop]);
}
}
Hope this helps
alternate
for( var x in friendId )
{
alert(friendId[x]); // this would be your desired value
}