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
WBOYOriginal
2016-08-04 08:53:201463browse

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>

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>

. 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

Statement:
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