如何从JavaScript函数传递一个值? [英] How to pass a value from javascript function?

查看:131
本文介绍了如何从JavaScript函数传递一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

如何将JS变量传递给php?

将javascript变量传递给php?

如何通过我有这样的代码

how to pass a valu from javascript function, I have this kind of code

function next(c,q){
    var y=Number(q);
    var x=Number(c)+1;
    var texta=document.getElementById('myText');
    var content=document.getElementById('woo'+x);
    var page=document.getElementById('paged');
    var thik=document.getElementById('lengthik');

    texta.value=content.value;
    page.value=x;
    thik.value=y;

    var z=100/y;

    //update progress bar
    $("#progressbar").progressbar("option", "value", $("#progressbar").progressbar("option", "value") + z);

    if($("#progressbar").progressbar("option", "value") < 100){
        $("#amount").text($("#progressbar").progressbar("option", "value")+"%");
    }
    else{
        $("#amount").text(100+"%");
    } 

}    

我想抛出新的将#progressbar的值放入php中。这个id是动态的,因为它是一个probressbar

and I want to throw the new value of the id #progressbar into the php. this id is dynamic because it is a probressbar

推荐答案

// post value of #progressbar id to my php page
$.ajax({
    url: myPHPPage.php,
    data: JSON.stringify({ progressbarID: '#progressbar' }),
    success: function (dataFromServer) {
        alert('it worked!');
    },
    error: function (jqXHR) {
        alert('something went horribly wrong!');
    }
});

这篇关于如何从JavaScript函数传递一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆