Home > Backend Development > PHP Tutorial > The value obtained by js-JS is posted to the PHP code.

The value obtained by js-JS is posted to the PHP code.

WBOY
Release: 2016-08-04 08:53:20
Original
1460 people have browsed it

jsphphtml

<code> <script>var images = document.getElementsByClassName("c1");var imageStr = "";for(var i=0;i<images.length;i++){   imageStr+=images[i].src+'_';}alert(imageStr);</script></code>
Copy after login

Run the above js after clicking the submit button, and then post the imageStr array to 1.php without returning

Reply content:

Quoting jquery’s ajax

<code> $("#id").click(function(){
           var imageStr;//你要发送的参数
            $.ajax({
                type:"POST",
                url:"1.PHP",
                data:{
                    IMGSTR:imageStr
                },
                dataType:'json',
                success:function(json){
                   //回调函数

                }

            });
 })
</code>
Copy after login

. Use ajax to transfer values, such as $.post (page, JSON format data, callback function);

This must be using ajax. There are many examples on the Internet and it will be fine

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template