Get value from AJAX using Javascript and ASP

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

    you can make the asp page write the result as JSON format read in directly via XMLHttpRequest Object and later processing:

    example of JSON

    var myJSONObject = {"bindings": [
            {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
            {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
            {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
        ]
    };
    

    then you can use native parsers in web browsers or eval() (NOT RECOMENDED, SERIOUSLY!!!) to parse the data written in your asp page and use it in your javascript client code.

    More information about JSON basic info

    JSON in browsers:

    • Internet Explorer 8+
    • Mozilla Firefox/Sea Monkey
    • in Opera, Chrome, Safari works too
    0 讨论(0)
  • 2020-12-02 01:54

    Here is a very good ajax tutorial. There is everything explained. https://developer.mozilla.org/en/AJAX/Getting_Started

    You forget a double quote:

    xmlHttp.open("post","CmsAjax.asp",true)
    

    To get the data:

    /* this puts the value into an alert */
    alert(xmlHttp.responseText);
    
    0 讨论(0)
  • 2020-12-02 01:57

    Whatever the server-side script outputs will be picked up by the AJAX request. So if the AJAX requests something, the server-side does the legwork and fetches the result from the database and then outputs it.

    There are loads and loads of tutorials on how to do exactly this. Just ensure that you secure your script properly so that it's not open to abuse.

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

    URL encode _data and nbquestions variables. Request.QueryString("param1") will decode them for you.

    JavaScript URLEncode:

    escape(_data);
    

    Also you can use Server.URLEncode() methods from VB script.

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

    You need to encode the data on the server and then decode them in the client. You can use JSON-RPC for this.

    Here are few links:

    Official Website

    Wikipedia Article about JSON-RPC

    Implementations of JSON-RPC Service in different languages

    But you don't need to use JSON-RPC if you have only one value you can encode as JSON in ASP and then decode it in JavaScript

    var array = JSON.parse(xmlHttp.responseText);
    
    0 讨论(0)
  • 2020-12-02 02:06

    When your Ajax-Request succeeds you will have the querystring-variables in the QueryString-Collection of the Request-Object.

    Could work like this on the server side:

    <% var newdata = Request.QueryString("value1"); %>
    
    0 讨论(0)
提交回复
热议问题