Get value from AJAX using Javascript and ASP

前端 未结 9 1016
轮回少年
轮回少年 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:

    <div id="willupdate"></div>
    <div id="willupdate2"></div>
    

    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);
    
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-02 02:14

    Client-side Javascript can't query server-based databases for obvious reasons. Based on what you appear to be doing, I would suggest you code an ASP which performs the actual query using VBA / C# / whatever, and you can then parse the results in your client-side ajax call as normal.

    0 讨论(0)
  • 2020-12-02 02:14

    xmlHttp.send correctly writen

    • It doesn't check that you have a 200 status before trying to deal with the data.
    • It fails to encode the data to make sure it is URL safe

    I would suggest using a library to handle XHR stuff, instead of reinventing the wheel. Microjs has a list of lots of small libraries if you aren't using one of the large ones (such as YUI or jQuery).

    how do I get the values on the server-side using Javascript.

    It is just query string data, so it will be in Request.QueryString.

    0 讨论(0)
提交回复
热议问题