How to call php script using jquery and terminate jquery script? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to execute a PHP script using jQuery and terminate jQuery at that point itself. I want the PHP script to be the last page on my browser rather than the jQuery page. I looked it up but every answer included the variable 'data' in it which I don't need. I'm not fetching data from PHP. I want to directly jump from jQuery to PHP and then end the program on the PHP file itself (I don't want to go back to the jQuery page to return some value from the PHP program). How can I do this?

I assume what you want to do is switch to the page ending .php instead of carrying out an ajax request to it and using the result. That doesn't require jquery and is simply done by setting globalThis.location or its href property like one of the following:
location = 'adjacent_file.php'
location.href = '/from/root/distant_file.php'
window.location.href = 'https://some.site/path/specific_file.php'
window.location = '... like the others ...'
Which of the above you pick is up to your needs and variable scope, but setting window.location will probably do you fine.
If you want to make a POST request that lands on the target page, there are a number of good answers already available for this other question - but you will need to create a form through vanilla JS or jquery and then submit it against the target page.

Related

the best way of passing variable from node to local javascript file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What is the best practice of passing data from node (express.js) to client javascript file? (not to ejs- just normal javascript file).
Example:
user type any word to input in page1.html
On backend I receive the word an redirect to page2.
on this page2 I have attached script (in a separate file)
The question is how to get the word in the separate javascript file attached to the page2?
One common way is to insert a script tag into the page that contains the variables you want to set: (As always, cleanse your data to avoid injections)
....
<script>
const myVar = 10; // modified by server, this is the value the user typed
</script>
....
<script> // uses myVar, your code here
if (myVar == 10) alert(1)
</script>
<script src="myscriptthatusesmyVar.js"></script>
Another option is to have the client JS request a special page that has the value as JSON data or something.
However, if you're trying to send lots of things and keep a connection between the server and the client while the user is on the page, I'd check out websockets
Edit: since there's a redirect, you have more options.
Page1:
https://example.com/page1.html
Say the user types in "abc123".
You can then redirect the user to https://example.com/page2.html?v=abc123 and read the query string.

How to scrape dynamic website in C#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to scrape https://public.rts.iebc.or.ke/enr/index.html#/Kenya_Elections_Senator/1
with HtmlAgilityPack. It is a dynamic site. The content is shown after the page loads completely.My code returns the HTML of the loading bar through this method while this method throws TargetInvocationException. I don't know how to make it wait until the page loads completely and then scrape it.
HtmlAgilityPack is just a library for .Net. You make a request and the library allows you to easily parse HTML response. If it does not contain the data you want to scrape then you need to do a different request. In the case of the page you mention, it uses Ajax for updating the page but Html is generated dynamically from a Json response. HtmlAgilityPack doesn't parse json but Html and this is a problem. If your code repeatedly makes requests for the same Url, you're going to get a new page every time with the original Html, which doesn't solve your problem neither.
If you're using WebBrowser you can wait using a timer.
With Selenium driver for .Net you need to set the timeout so that it will keep trying to find an element for a while before raising not found exception.

Which is faster ..passing variables to a javascript function or running a MySql query to fetch the values? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I wish to know the following: Which one of the following is faster- passing variables to a javascript function and then passing it on to a php file to carry out some operation or running a MySql query to fetch the variables in the php file without passing them? ..Thanks a lot!
For pretty similar request .. if the related value are already available to te client and you need this to some other page then tecnically
the javascript ajax request involve only the internet transfer of the call and the transfer of the result .. the use of database access in addition to sending the request and receiving data also implies the access to the database so normally should be more fast ths ajax method
Unless you have a specific reason for using Javascript, for instance, updating displayed records without reloading the page, use PHP directly. You can always run the php function in a class on a separate file if you wish to keep your html and php separate.
My personal experience of ajax, which you should remember still has to access PHP in order to execute server-side requests, is that it can appear slow. Whether or not it actually is slower, it leaves the page in place whilst executing the code and so might present that illusion to the user.
Also, I think the simplest solution is the best, so if you don't need ajax you shouldn't use it, but if you do need it then there is no reason not to do so that I am aware of.

Assign ajax Response to PHP variable to use if further [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a ajax response, which contains 3 variable(a,b,c=array() ) in json Array,
i want to assign c to a php variable so that i can use it further.
Is it Possible if so then how can i do it?
I want to use this array of php to refresh a list In my View.
By the time an AJAX call has returned a response to the browser, the PHP code has finished executing, so you will not be able to run any more PHP after this except by making another AJAX request.
If the html that makes up the list that you want to refresh is produced by a PHP view then you have two options.
1) Run the PHP code before your AJAX response is returned. That way your ajax response could be something like:
{"a":value,"b":value,"c":array,"d":"<ul>... updated list html code</ul>"}
You can then use JavaScript to replace the old HTML with your refreshed view stored in d.
2) You could store the value of c in a JavaScript variable where it can be re-used in a future AJAX request which will return the view HTML.
Hope this helps.

How to get access to cross domain content? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Two webpages, http://website.com/home.php and another one is on my dropbox http://dropbox.com/myId/public/myfile.html.
I want to run a user script (which will be given out to other people) on home.php with some values, basically some 9-10 numbers. These values are already defined in the script. But they have to get updated on a regular interval, this is done by the user clicking a link or something. These updated values will be on myfile.html. I have full control over this file.
I have tried using localStorage in the script but that doesn't allow to share content over different domains. iframe also doesn't work due to cross domain. But is there a way that these values can be released by a function() on need.html when the iframe loads on home.php?
I'm pretty new to javascript, so I don't know everything.
What you need is JSONP. Here is more on that
I found out how to do it:
I created a script element using the userscript in home.php which links to need.js instead of need.html.
need.js contains code to add the "values" to localStorage.

Categories

Resources