javascript - JS POST to PHP.

WBOY
Release: 2016-08-04 09:19:31
Original
2004 people have browsed it

<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
Copy after login

How to set a button and post the array in imageStr to PHP after clicking it

<code>$imageStr = "http://127.0.0.1/down/123.gif__http://127.0.0.1/down/8095680852_893f685cbd_q.jpg__http://127.0.0.1/down/8018953043_c6ef9e3b29_q.jpg__";
</code>
Copy after login
Copy after login

Please search for relevant answers before asking questions:
https://segmentfault.com/sear...

Reply content:

<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
Copy after login

How to set a button and post the array in imageStr to PHP after clicking it

<code>$imageStr = "http://127.0.0.1/down/123.gif__http://127.0.0.1/down/8095680852_893f685cbd_q.jpg__http://127.0.0.1/down/8018953043_c6ef9e3b29_q.jpg__";
</code>
Copy after login
Copy after login

Please search for relevant answers before asking questions:
https://segmentfault.com/sear...

Example

<code>$( "#lock_submit").click(function (){
 var lock_form = $("#lock_form").serialize(); // 参数带在form里面用form表单
 var onePush = "xxx/xxx/xxx.php" ;
 var imageStr ="http://127.0.0.1/down/123.gif__http://127.0.0.1/down/8095680852_893f685cbd_q.jpg__http://127.0.0.1/down/8018953043_c6ef9e3b29_q.jpg__";
    $.ajax({
        url: onePush ,
        type:"POST",
        data:{image:imageStr},//data:lock_form  form提交
        dataType : "json",
        success :function(data){

            if(data.status== 1){
                alert('操作成功')
                // 刷选页面
                location. reload();

            }else{
               alert('操作失败')
            }
        }
    })
})
</code>
Copy after login

Just submit the form

$.post(url,{imageStr:$imageStr},function(res){

<code>//do somethings
</code>
Copy after login

})

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