url in javascript - javascript

This is a javascript geo-target code:
<script src='http://promos.fling.com/geo/txt/location.php?testip='></script>
Is possible add the results of it in the end of URL?
Fairfield, CT
The javascript result put after ?q=
Thanks!

You can assign a value to location.search. Anything you assign gets placed in front of the ?. You may need additional parsing to extract or append specific values and reconstruct it to form a query string. Note that the page will refresh when doing so.

Related

How to substring variable and concatenate it with url in Thymeleaf

I want to substring a variable which is my JPA class id field and then add it to an URL in Thymeleaf.
My URL is like
/Myapplication/sortddoc/value=__${entity.id}__
So I need to do something like
${entity.id}.substr(0, 8)
before concatenating it to the URL.
I tried to create a new Transient field in my entity class containing the substring variable but it doesn't work because it seems like to need database field that I cant provide.
Can Anyone help me, please ?
You should be doing this with Thymeleaf's standard URL syntax, instead of concatenating string variables or using preprocessing (there is no need for either of those).
<a th:with="${value=#strings.substring(entity.id,0,8)}"
th:href="#{/Myapplication/sortddoc/(value=${value})}"></a>
or
<a th:href="#{/Myapplication/sortddoc/(value=${#strings.substring(entity.id,0,8)})}"></a>

Issue with picking multiple JSON

I have recorded a script and "search" an id from it.
I have performed the following things
Have parametrize the "searcID" so that it can be picked from the "CSV_Data Config"
Have extracted the "key" from the URL through "Regular Expression Extractor" to provide it to the desired URL requiring "key", so that it can be dynamic
Now the issue is, since the script is recorded for one search id, in "/build-4.4.10.0/SECChecker/Search/Html?_dc=0.5557150364018139&Grid-Ajax", the last line of my script has a body of the one recorded "searchId".
The script runs and return for each thread this same result of JSON (that is present in the last line i mentioned), i want this too to be dynamic, how can i do that? Please guide
If you want to parametrize the last request, you should use the following notation: ${"var name"} and use a CSV manager. link2
for instance, if you want to parametrize the fist param of the body you should have something like this:
{"SortField":"${var_name}",....
One thing, the dc param, part of the path, looks like a random used to avoid cache, so I use this to simulate the requests during the test:
.../Html?_dc=${__RandomString(15,0123456789)}&Grid-Ajax
This function returns a string which its length is 15 (1st param) and has a set of numbers (2nd param)
Hope It helps you.

pass multidimensional javascript array to another page

I have a multidimensional array that is something like this
[0]string
[1]-->[0]string,[1]string,[2]string
[2]string
[3]string
[4]-->[0]string,[1]string,[2]string[3]string,[4]string,[5]INFO
(I hope that makes sense)
where [1] and [4] are themselves arrays which I could access INFO like myArray[4][5].
The length of the nested arrays ([1] and [4]) can varry.
I use this method to store, calculate, and distribute data across a pretty complicated form.
Not all the data thats storred in the array makes it to an input field so its not all sent to the next page when the form's post method is called.
I would like to access the array the same way on the next page as I do on the first.
Thoughts:
Method 1:
I figure I could load all the data into hidden fields, post everything, then get those values on the second page and load themm all back into an array but that would require over a hundred hidden fields.
Method 2:
I suppose I could also use .join() to concatenate the whole array into one string, load that into one input, post it , and use .split(",") to break it back up. But If I do that im not sure how to handel the multidimensional asspect of it so that I still would be able to access INFO like myArray[4][5] on page 2.
I will be accessing the arrary with Javascript, the values that DO make it to inputs on page 1 will be accessed using php on page 2.
My question is is there a better way to acomplish what I need or how can I set up the Method 2 metioned above?
This solved my problem:
var str = JSON.stringify(fullInfoArray);
sessionStorage.fullInfoArray = str;
var newArr = JSON.parse(sessionStorage.fullInfoArray);
alert(newArr[0][2][1]);
If possible, you can use sessionStorage to store the string representation of your objects using JSON.stringify():
// store value
sessionStorage.setItem('myvalue', JSON.stringify(myObject));
// retrieve value
var myObject = JSON.parse(sessionStorage.getItem('myvalue'));
Note that sessionStorage has an upper limit to how much can be stored; I believe it's about 2.5MB, so you shouldn't hit it easily.
Keep the data in your PHP Session and whenever you submit forms update the data in session.
Every page you generate can be generated using this data.
OR
If uou are using a modern browser, make use of HTML5 localStorage.
OR
You can do continue with what you are doing :)

How to get parameter from hash url?

On some of my pages, I have a hash in the url like this: http://localhost/#/products/6959
How can I check if I have a product ID available and so I can save it in a variable to use later? Any help would be greatly appreciated!
You want a regexp to extract the number at the end of the url in javascript?
"http://localhost/#/products/6959".match(/[0-9]+$/);
Edit: Or if you want to make sure this is products:
"http://localhost/#/products/6959".match(/products\/([0-9]+$)/)[1]);
The parenthesis indicate a matching group that you find in [1].
You should be able to get that id out of the URL through accessing the params variable. In this case, params[:id] should do the trick.
Also, I do not recommend using a regex.

Auto Complete does not filter results when I'm typing

I have very simple form that gets values in JSON format from searchAlbum.php. It works when I start typing something in, but it does not filter results, for example it shows 123 as available even though I typed ab.
This is what my saerchAlbum.php is returning
["123","abc"]
This is my Java Script code
$(document).ready(function(){
$('.albumName').autocomplete({
source: 'searchAlbum.php'
});
});
You might say that it should not filter my resoulds and I need to pass my input as a paramater but why then this examle on jquery-ui page does that for me?
The documentation isn't clear about it, but the only time the autocompleter does the filtering for you is when your code isn't getting called at all (e.g., you've given it an array as source). When your code is getting called (either client-side code because you've given a function for source, or server-side code because you've given a URL), your code is expected to do the filtering.
You might say that it should not filter my resoulds and I need to pass my input as a paramater but why then this examle on jquery-ui page does that for me?
Because the search.php page that the example calls filters the results based on the term parameter the autocompleter passes it. Compare the results you get from these:
http://jqueryui.com/demos/autocomplete/search.php?term=ti
http://jqueryui.com/demos/autocomplete/search.php?term=ro
You can see that it's filtering server-side.
The js sends a query string parameter named "term", your php code needs to return data by filtering existing data that match the "term" parameter.
This isn't a Javascript or jQuery problem, but a PHP problem. As mentioned in the linked jQuery-UI page, the source script must process the "term" property via a GET request.

Categories

Resources