I'm working on an AJAX application that uses Knockout and Sammy for AJAX history. The application uses a set of filters, sort options and pagination to let the user search trough 35000 records.
Currently the URL hash is in the following form:
http://domain/Search/{SearchTerms}/PageIndex
For example:
http://localhost/search/#0%20-%205%C4%80square%20meter/1
The search terms are parsed on the server to match them to the available filters. I can't use an Id or something because the filter set is rebuild each day (when backend data updates) and the only thing that stays the same is the description.
This is the javascript code to build the hash:
var hash = '';
ko.utils.arrayForEach(self.SelectedItems(), function (item) {
hash = hash + item.Description + ' ';
});
hash = encodeURIComponent($.trim(hash));
hash = hash + '/' + self.HuidigePagina();
location.hash = hash;
The problem is that joining all the item descriptions can become really long. Is there a way I can compress this part and then decompress it when I send it to the server in javascript?
I've found some answers here on stackoverflow that uses LZW compression, but it didn't give me my original string back.
Related
This is how my site is constructed...
articles.php contains the layout html to display all articles for a category.
articles.js contains the control elements to obtain db query results and pass to articles.php page. Within the js script is a dataTable that is displayed on the articles.php page.
ajax_articles.php contains the query request and return json file results of the query. Within the json file are links to the individual articles. The link is structured as a clean SEO URL (e.g., article/001/moby_dick).
This is how I understand htaccess to work.
When a user selects an article the URL (i.e., https://www.example.com/article/001/moby-dick) is passed through htaccess and with a RewriteRule ^article/([0-9]+)/([a-z_-]+) article.php?art_id=$1&art_name=$2 [NC,L] will display the SEO 'pretty' URL, BUT known to the system will be the URL containing the two parameters that can be used by a $_GET to obtain the two parameters. IS MY UNDERSTANDING OF THE PROCESS CORRECT?
I've noticed that with the htaccess I now have to use the full path name to load the support (.js) and graphic files. Further, I cannot obtain the variables via js $_GET.art_id and $_GET.art_name.
Any assistance is greatly appreciated.
You can't access the GET variables with javascript in this configuration because they do not exist after the URL rewrite. The query parameters have been removed.
There are still ways you can extract these values from the URL with window.location.href and the .split() method in javascript.
// var myurl = window.location.href; // this will get the string of your current URL. Used manual string in this example
var myurl = "https://www.example.com/article/001/moby-dick"; // manual URL for sake of an executable example
var spliturl = myurl.split("/"); // ["https:","","example.com","article","001","moby-dick"]
var articleid = spliturl[4]; // "001"
var articlename = spliturl[5]; // "moby-dick"
// see the variables in action
console.log("id: ", articleid);
console.log("name: ", articlename);
Could you help me do the task using JavaScript?
I have a task and if i do it manually it looks like this:
i create Saved Search in NetSuite.
Download the result of created saved search in csv.
The i put this file on ftp server, using FileZilla. (i had a connection with server previously: write a domain, username and password - that's all)
Now, a need it solve through sutlet script.
1. Create Saved Search - done
2. Create csv with result of saved search in content and put it in file cabinet in the NetSuite - done
3. Ok, now i have a needs me file but i do not understand how to pass it on ftp.
*i tried to study several articles, but frankly speaking could not to solve my problem. Moreover, their article seems about manually method not automative
this aritcle - https://ursuscode.com/netsuite-tips/suitescript-2-0-sftp-tool/*
var searchResult = Contacts.run().getRange(0,999);
log.debug('Contacts', searchResult);
var Header = 'INTERNAL ID' + ';' + 'FIRST NAME' + ';' + 'LAST NAME';
var Content = "";
for (var i = 0; i < searchResult.length; i++) {
var internalid = searchResult[i].getValue('internalid');
var FirstName = searchResult[i].getValue('firstname');
var LastName = searchResult[i].getValue('lastname');
Content = Content + internalid + ';'
+ FirstName + ';'
+ LastName;
Content = Content + '\n';
}
var fileObj = file.create({
name: 'test.csv',
fileType: file.Type.CSV,
contents: Header + '\n' + Content
});
fileObj.folder = 45434;
var fileId = fileObj.save();
var savedFileObj = file.load({
id: fileId
});
var myPwGuid = '';
var myHostKey = ''
var objConnection = sftp.createConnection({
username: '',
passwordGuid: myPwGuid,
url: 'ftp.expertsender.com',
hostKey: myHostKey
});
NetSuite does not support ftp, it only supports sftp.
NetSuite has the support for SFTP, FTP and SFTP runs in different port numbers, However FTP transfers data in plain text format which will compromise your security, using SFTP is the better option as it will transfer your data in encrypted format and security is assured.
In your example, I believe you're calling FTP request which will not work in this case.
Oki,
Now, the article you did mention is the right one : why ? Because the first required step to be able to use SFTP is to generate a GUID. You are talking about manual methods, well yes, including the one in that Article, but it is not a problem, because once you have generated the GUID, you don't need to change it, so it is a one time action, unless your ftp credential change.
So, first step : use "ursuscode" to create a Suitelet. Deploy that suitelet and use it to generate the GUID (it is a form where you need to set the ftp password, host...). Using the same form, you can then generate the HOST key (check the video).
Second step, use the Generated GUID and HOST Key in your code.
Third step, add the code to upload the file : from netsuite help page, here is an example:
connection.upload({
directory: 'relative/path/to/remote/dir',
filename: 'newFileNameOnServer.js',
file: myFileToUpload,
replaceExisting: true
});
By the way, you can upload the file without the need to Save and Reload it again (https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4617004932.html).
Note: remember that this is an SFTP, so probably support only SFTP not FTP.
Suggestion: About the GUID (and the other data needed for the connection), I suggest that you use a Script Parameter to provide the GUID to your script code, so if your password change, you can regenerate the GUID and update the script parameter value without the need to touch your code.
Hope this helps!
Background: I have little knowledge of javascript, only html and css.
My Problem: I have a dynamic table on my webpage (WPDataTables) that includes a global search and then column specific search. My users can type into these searches and the content will dynamically update. My problem is the URL does not update to include search parameters so we cannot copy and send URL's to other people that include specific search results.
WpDataTables currently has the following keys to pre filter the table:
Global: ?wdt_search=filtervalue
Column: ?wdt_column_filter[ColumnName]=filtervalue
This is great but my users aren't savvy enough to create their own URL strings and there are a large number of possible filters so pre-creating each one is not an option.
Currently: I am close to getting a solution, I think, with the following:
<body>
<button onclick="updateURL();">Update</button>
<script type="text/javascript">
function updateURL() {
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?para=hello';
window.history.pushState({path:newurl},'',newurl);
}
}
</script>
</body>
Ideally, with this the user will simply click the Update button to update the URL with the current search parameters. The problem is ?para=hello is just a hard coded parameter and I can't figure out how to get it to be dynamic and change with the users searching/filtering.
My website: http://imsched.com/sailings
The query string can't be updated without reloading the page. If you want to track those updates in the url so they are shareable, and still have them affect your filters you could use the hash instead. The hash can be easily read and you can update it without reloading the page.
// to read
window.location.hash
// to update
window.location.hash = 'param=value¶m=value'
If you had a url like this http://url.com#1=one&2=two&3=three, you could do the following:
var filters = window.location.hash.split('&')
// filters now = ['1=one', '2=two', '3=three']
// so you can make easy use of those
Update
If you need to update the query string and don't mind that it reloads the page each time, you can manipulate it via window.location.search
// to read
window.location.search
// to update (will reload the page)
window.location.search = window.location.search + '&your_stuff=here'
A function that could build your query string from your filter fields could look like this:
function buildQuery() {
var inputs = [].slice.call(document.querySelectorAll('.js-filter'))
return inputs.reduce(function(str, el, i) {
return str + (i > 0 ? '&' : '') + el.name + '=' + el.value
}, '')
}
Example fiddle here
You can try use HTML5 History Manipulation:
https://css-tricks.com/using-the-html5-history-api/
It's more commom with AngularJS, etc...
Sorry, the above solution didn't work for me you can try this:
window.location.pathname.replace(/[^a-zA-Z ]/, "");
http://www.biletix.com/search/TURKIYE/en#!subcat_interval:12/12/15TO19/12/15
I want to get data from this website. When i use jsoup, it cant execute because of javascript. Despite all my efforts, still couldnot manage.
enter image description here
As you can see, i only want to get name and url. Then i can go to that url and get begin-end time and location.
I dont want to use headless browsers. Do you know any alternatives?
Sometimes javascript and json based web pages are easier to scrape than plain html ones.
If you inspect carefully the network traffic (for example, with browser developer tools) you'll realize that page is making a GET request that returns a json string with all the data you need. You'll be able to parse that json with any json library.
URL is:
http://www.biletix.com/solr/en/select/?start=0&rows=100&fq=end%3A[2015-12-12T00%3A00%3A00Z%20TO%202015-12-19T00%3A00%3A00Z%2B1DAY]&sort=vote%20desc,start%20asc&&wt=json
You can generate this URL in a similar way you are generating the URL you put in your question.
A fragment of the json you'll get is:
....
"id":"SZ683",
"venuecount":"1",
"category":"ART",
"start":"2015-12-12T18:30:00Z",
"subcategory":"tiyatro$ART",
"name":"The Last Couple to Meet Online",
"venuecode":"BT",
.....
There you can see the name and URL is easily generated using id field (SZ683), for example: http://www.biletix.com/etkinlik/SZ683/TURKIYE/en
------- EDIT -------
Get the json data is more difficult than I initially thought. Server requires a cookie in order to return correct data so we need:
To do a first GET, fetch the cookie and do a second GET for obtain the json data. This is easy using Jsoup.
Then we will parse the response using org.json.
This is a working example:
//Only as example please DON'T use in production code without error control and more robust parsing
//note the smaller change in server will break this code!!
public static void main(String[] args) throws IOException {
//We do a initial GET to retrieve the cookie
Document doc = Jsoup.connect("http://www.biletix.com/").get();
Element body = doc.head();
//needs error control
String script = body.select("script").get(0).html();
//Not the more robust way of doing it ...
Pattern p = Pattern.compile("document\\.cookie\\s*=\\s*'(\\w+)=(.*?);");
Matcher m = p.matcher(script);
m.find();
String cookieName = m.group(1);
String cookieValue = m.group(2);
//I'm supposing url is already built
//removing url last part (json.wrf=jsonp1450136314484) result will be parsed more easily
String url = "http://www.biletix.com/solr/tr/select/?start=0&rows=100&q=subcategory:tiyatro$ART&qt=standard&fq=region:%22ISTANBUL%22&fq=end%3A%5B2015-12-15T00%3A00%3A00Z%20TO%202017-12-15T00%3A00%3A00Z%2B1DAY%5D&sort=start%20asc&&wt=json";
Document document = Jsoup.connect(url)
.cookie(cookieName, cookieValue) //introducing the cookie we will get the corect results
.get();
String bodyText = document.body().text();
//We parse the json and extract the data
JSONObject jsonObject = new JSONObject(bodyText);
JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONArray("docs");
for (Object object : jsonArray) {
JSONObject item = (JSONObject) object;
System.out.println("name = " + item.getString("name"));
System.out.println("link = " + "http://www.biletix.com/etkinlik/" + item.getString("id") + "/TURKIYE/en");
//similarly you can fetch more info ...
System.out.println();
}
}
I skipped the URL generation as I suppose you know how to generate it.
I hope all the explanation is clear, english isn't my first language so it is difficult for me to explain myself.
I am collecting data from a user on Server A,
I need to send that data in a URL to server B (separate buildings and companies)
On server A it is a CRM system which is pre built and I cannot just simply use PARAMETERs as I cannot HASH the PARAMETERs as the system is pre built by a third party and they would charge to allow for this.
So I have managed to build some JS that replaces certain characters from the PARAMETERs I can collect.
Here is a small snippet of what I have to make my HASH.
<script type="text/javascript">
// Collect USERID
var m = 'XX784188';
// HASH USERID
m = m.replace(/7/g, 'M');
m = m.replace(/4/g, 'S');
// Set up Object n as Location name.
var n = 'Cumbria';
// Rename Location to correct code
n = n.replace(/[Cumbria]/g, '01');
// Test Object m & n
alert(n);
alert(m);
Here is the above in a test.
Now what I cannot seem to find out is how do I insert the results into a url and redirect the user to that URL.
For example:http://google.com/?n=&m=
I can insert this line I know for the redirect:
window.location = "http://google.com/?n=&m="
I just need to know how I make that URL look like this google.com/?n=01&m=XXM8S188
Funny, I just answered the same thing 1min ago :
window.location = "http://google.com/?n="+n+"&m="+m
Your snippet code and JS Fiddle code are different.
For snippet code then you simply insert your values like,
window.location = "http://google.com/?n="+n+"&m="+m;
For JSFiddle code, then,
window.location = "http://google.com/?"+serialiseObject(obj);