How PHP calls the JS method

Source: Internet
Author: User
Form form submitted to the background PHP processing, after processing needs to call the day before yesterday JS a method to show a pop-up layer, but the hint error can not find this JS method, call method is directly echo a section of JS code.


Reply to discussion (solution)

Should be in the background PHP page to introduce this JS method.
And it seems that HTML click to submit the form has been left this page.
Unless you do an Ajax method, do not form. Direct AJAX submissions.
Click the button to trigger Ajax. This will not refresh the original HTML.
Trigger pop-up layer can be written in Ajax onreadystatechange

First introduce JS file

PHP to be executed first, and then sent to the client, you must not find your JS method

Submit with Ajax

The code is posted for analysis, and the error message is also posted.

In your echo this JS method before you write JS introduced

Is this "JS method" only on the form page or on the form target page?

You need it. It's confusing!!!

Either this JS code is not loaded, or the code is defined in a local environment.

How does PHP invoke the JS method??
A run on the server side of a run on the front end, from the server side you initiated the request to run PHP script to return the results of both do not intersect what to call!
The HTML documents before and after the form submission are different, either by using AJAX to request the PHP script to get the data and then using your JS method, or in the production of PHP after the completion of the new page inside processing.

PHP call JS, I generally directly echo "";

is the echo direct output.
The method you can't find is because you did not refer to the definition of your JS method before the Echo output script.

Processing method: 1, you output the JS format right, JS method must have wrapped up
2, the method you output has not been introduced.
Suggest you first output an alert to try, if this is not a problem, you can pop up the form, it means that the method is wrong, or did not introduce JS.

Summarize:
It's really easy to do this with Ajax, but it doesn't happen, but you can't use Ajax if you need to upload a picture. So I'm using the form submission target pointing to a hidden iframe
I tried to use the load JS file before echo, so the problem is that the popup layer gets it, but it doesn't show the current page, but instead prints it to the hidden iframe.
Finally, a compromise method is used, which is displayed directly on a newly opened page.

Above thank you for answering questions!

Landlord This problem I am also looking for solutions to the solution you found it? I tried to use the load JS file before echo, so the problem is that the pop-up layer is acquired, but can not display the current page is not get the current page tangled

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.