passing the parameter along with the url and getting the result back - javascript

Is it possible to get the result on calling a url and passing the respective parameters along with the url?
For example suppose I pass two nos along with the url and I get the sum back.
The sum is calculated in the called url page

Yeah, data can be sent as URL variables. This is what happens when you use a form which is using "GET"
e.g.
https://www.google.co.uk/?q=example
you are passing "example" as the search term inside the URL
if you want to read up about it properly, have a read through this Post on MDN

Related

How can I retrieve an array inside a string that is a function?

I need to pick up the objects from this service.
http://www.geonames.org/childrenJSON?geonameId=3469034&callback=listPlaces&style=long&noCacheIE=1543532747264
but they are coming in one kind of function js
how can I get the value of the geonames attribute ??
The data format you are looking at is JSONP (which is what we used to work around the Same Origin Policy before CORS was designed).
Remove the callback query string parameter from the URL and the service will return plain JSON instead. You can then parse that as normal.
In the url you have &callback=listPlaces. If you take that out you'll get the actual object. It looks like you're expected to have the name of the callback you passed it defined in your code, and by passing callback as a param its returning the actual function call.

Getting string index value from Javascript to MVC C# Controller using string[] array as a parameter

I am new in this environment and i just want to ask somebody if it is possible to get the string value not the index value using string[] array as a parameter?
Below are those images: ajax pass this data into controller
I am using ajax to pass my data in to the url controller in c# mvc.
By the way, here's my sample array data: prepared data..
the highlighted one is my array and in my parameter in mvc # is declared as string [] methodParam: highlighted parameter,
Those not highlighted parameter are working. all i want to do is getting one by one string in methodParam. i tried to use this
GetMethodParam.IndexOf("Date").ToString() but the output is -1 which probably not available in context.
i just want to get each string and its value because i send it to the email outlook..
like this. enter image description here.
Any Suggestions, clarification or comments is highly appreciated. Thank you ;) .
You don't need the individual input in data on ajax call, just use the last one UserHeader
and in Acton(C#) use a model as argument with containing all attributes of UserHeader.
Or, remove UserHeader from data and Use each attributes as individual argument in C# Action with same name.

how to use javascript to invoke the value of an html special data attribute and pass to php array in yii 1.1.14?

I have an anchor link where the data-url has a value of a yii create url like this
CLICK ME
so the situation is like this, you see the data-chosen-type="" attribute?, the value is actually being set by a javascript. Now what I want to happen is, grab the value of data-chosen-type attribute and place it to 'var3' value, within the array inside that createUrl thing. So the output should be like this
CLICK ME
is that possible to do?
I tried doing this
'var3' => "js:$('#download-button').attr('data-chosen-type')"
it didn't work, but in a view file especially in CGridView, putting javascript in a value of a key pair does work...how come in createUrl I wasn't able to do the same thing? am I doing it wrongly?
No, that is not possible, because PHP is long done before anything JavaScripty happens on the client.
If you can not determine the value on the server-side at all - then make an AJAX request to the server, so that you can call the createUrl method there with the correct parameters, and then set the link data-url attribute with the returned URL.

AngularJS While Add location parameter it should maintain previously inserted

When i add parameter using $location in url as shown below it first removes added data but i want to keep that previous data...
Example with code
Main url:
http://localhost/angular_laravel/angjs/#/bag_list
when i do this,
$location.path('/bag_list').search({category: cat_search});
it simply changes url to this,
http://localhost/angular_laravel/angjs/#/bag_list?category=1
now when next function doing something like this,
$location.path('/bag_list').search({model: model_search});
and then url changes to this,
http://localhost/angular_laravel/angjs/#/bag_list?model=1
but i want to keep both like this,
I WANT LIKE THIS:
http://localhost/angular_laravel/angjs/#/bag_list?model=1&category=1
My problem is that it deletes previous parameter but i want to keep that parameter,
any help...??
You have 2 options I believe.
If you are only setting a single value (as you are in the example) you can use the 2 argument form of the setter. eg.
$location.search('model', model_search);
If you need to set more than 1 (or your data is coming in as an object already) you can manually merge the values. eg.
$location.search(angular.extend({}, $location.search(), { model: model_search }));
Try:
$location.path('/bag_list').search({category: cat_search, model: model_search});

AJAX Post missing variable

Im using an ajax call like so:
o.open("POST",q,true);
o.setRequestHeader("Content-type","application/x-www-form-urlencoded");
o.setRequestHeader("Content-length",p.length);
o.setRequestHeader("Connection","close");
Where q = the url and query string.
p = the query string only.
My query takes the form of: "/apps/nettrax/f/events_detail.php?get=1&ids="+multiple values added like this: 123~34567~567~678~etc
This all works if there are a few values, but large value strings fail - the variable ids does not pass (although get is passed)...
* Im not using jquery.
You're sending a POST request, but specifiying the parameters in GET via the URL. There's a limit on the size of URLs, so this won't work. You should be passing the parameters in the send() call, so that they are specified as POST data:
var parameters = "ids=" + encodeURIComponent(ids);
o.open("POST","events_detail.php",true);
o.setRequestHeader("Content-type","application/x-www-form-urlencoded");
o.setRequestHeader("Content-length",p.length);
o.setRequestHeader("Connection","close");
o.send(parameters);
I guess one this two things may be happening:
a) your url string is too long, so it's beeing truncated
b) your parameters are not encoded as the url needs to be, so the string "breaks" the url. if using php use a function like urlencode() or build your own one.

Categories

Resources