Get value from AJAX using Javascript and ASP

前端 未结 9 1067
轮回少年
轮回少年 2020-12-02 01:44

I am using this Ajax code. But I dont know how i will retrieve my value of value1 on my server-side asp using Javascript.

On my serverside I want to have something

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 02:11

    //(javascript, ajax = xmlHttp)
    

    if your response text is an array you can use this.

    var myArray = eval(xmlHttp.responseText);
    

    or if it is a just text you can use .

    var value = xmlHttp.responseText
    

    Another approach.This is just a template. If you use jquery, you can use this approach. i hope it solve your problem or give an idea.

    html part:

    JQuery part:

     $(document).ready(function() {
    
    getValue("serverurl",updateName)
    getValue("serverurl",updateSurName)
     });
    
    function updateName(name){
     $("#willupdate").text(name)
    }
    
    
    function updateSurName(name){
     $("#willupdate2").text(name)
    }
    
    function updateSurName(name){
     $("#willupdate").text(name)
    }
    
    function getValue(url,opt_onRecieved){
        if( !url || url == ""){
            alert("request url error");
            return;
        }
    
        $.ajax({
            type:"POST",
            url: url,
            dataType:"json",
            success: function(data){
                opt_onRecieved(data);
    
            }
        });
    }
    

提交回复
热议问题