SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Chicago
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX - problems passing parameters to server page

    ------------
    first ajax page
    ---
    function makePOSTRequest(url, parameters)
    {
    if ((url == null) || (parameters == null)) return;
    if ((url.length == 0) || (parameters.length == 0)) return;

    http_request = false;

    if (window.XMLHttpRequest)
    {
    // Mozilla, Safari,...
    http_request = new XMLHttpRequest();

    if (http_request.overrideMimeType)
    {
    // set type accordingly to anticipated content type
    http_request.overrideMimeType('text/html');
    }
    }
    else if (window.ActiveXObject)
    {
    try
    {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    try
    {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {}
    }
    }

    if (!http_request)
    {
    alert('Cannot create XMLHTTP instance');
    return false;
    }
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.onreadystatechange = alertContents;
    http_request.send("parameters");
    // parameters: radiobtn=401&choice=blah%20blah&mood=123&url=/root/setup.asp&userid=ajaxASK999

    return true;
    }

    function alertContents() {
    if (http_request.readyState == 4)
    {
    if (http_request.status == 200)
    {
    result = (http_request.responseText);
    document.getElementById('pollResults').innerHTML = result;
    // pollResults is the id of span from the form
    }
    else
    {
    result = http_request.responseText;
    }
    }
    }

    -----------
    setup.asp
    ---
    <%
    id = request.querystring("userid")
    response.write(id)
    %>


    I'm trying to use ajax to pass a collection of form values to a server page (asp). Update the database and pass the result back from the database.
    All seems to be working, except the major problem is this is not passing the parameters to the server page. The request.querystring("userid") is not receiving any data from the ajax code on the first page. What is it that i'm doing wrong?

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uncomment the variable paramaters in your http_request.send("parameters");
    It should be http_request.send(parameters); because it's a variable.
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Chicago
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good catch, i was excited to fix a new error.
    but asp is still not rechieving the parameters.

    on top of that im getting a new error on server page, when it gets to the database query to insert the data. it generate status=500 error

    --------------
    adding data to pollTable (for testing --i manually set the value - if the length for the parameters passed from ajax page is null)
    ----
    strvote5 = "INSERT INTO pollTable(pNum, answerNum, pollDate,userName,userID) "
    strvote5 = strvote5 & "VALUES ('"&parameters1&"','"&parameters2&"',"&now()&",'"&parameters3&"','"&parameters4&"') "
    Set rsvote5 = Server.CreateObject("ADODB.Recordset")
    rsvote5.Open strvote5,DBConnection,adOpenDynamic,adLockOptimistic

  4. #4
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry mate, ASP is still a language on my to-learn list
    FOR SALE: 1 set of morals, never used, will sell cheap

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Chicago
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the application is working. so happy
    ty ty


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •