Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Using prototypes Ajax parameters, how do I get ":" in the url?

    Hey, I am using prototypes (library) ajax methods and one of them is properties.

    I am passing in the name value pairs:

    var itemFilter = "MajorCat: Shoes",
    parameters: { q : qry ,fq: itemFilter },


    But when I request, it gives me this in the url:
    MajorCat%3AShoes

    That won't work, the search application on the backend doesn't filter properly because of the "%3A" instead of ":".

    When I manually pass in via the url: MajorCat: Shoes (at the end of the query) it works.

    So, that ":" is getting encoded. How do I get that IN the hash and make sure the request is unencoded when it goes out?

    thanks
    Last edited by BrightNail; 10-07-2011 at 10:53 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    you should encode before sending:
    Code:
    <script type="text/javascript">
    
    var uri="my test.asp?name=ståle&car=saab";
    document.write(encodeURI(uri)+ "<br />");
    
    </script>
    and decode when recieving:
    Code:
    <%
     name = new String(decodeURI(Request("name")))
    %>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Code:
    function getSearch( qry ) {
    var itemFilter = "MajorCat: Shoes";
         var opt = {
            method: 'get',
            parameters: { q : qry ,fq: itemFilter },
            onSuccess: function(t) {
                var data = t.responseText.evalJSON().response.docs;
               // do some work
            }
        }
        new Ajax.Request('serverpathhere/json/shoes', opt);
    So, given that, how would I encode it -- but I believe the js prototype "is" encoding on its own because I am passing ":" but the url request string has the "%3A" , so I need it to be ":"

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Well, I don't know the intricacies of the library, but I would also expect it to decode... but if your saying that it didn't, try to do it manually
    Code:
    function getSearch( qry ) {
    var itemFilter = "MajorCat: Shoes";
         var opt = {
            method: 'get',
            parameters: { q : qry ,fq: itemFilter },
            onSuccess: function(t) {
                var data = t.responseText.evalJSON().response.docs;
                data =  decodeURI(data)
               // do some work
            }
        }
        new Ajax.Request('serverpathhere/json/shoes', opt);
    but that might not work either... I might try to decode the data befor the evalJSON:

    Code:
    function getSearch( qry ) {
    var itemFilter = "MajorCat: Shoes";
         var opt = {
            method: 'get',
            parameters: { q : qry ,fq: itemFilter },
            onSuccess: function(t) {
                var data = decodeURI(t.responseText).evalJSON().response.docs;
               // do some work
            }
        }
        new Ajax.Request('serverpathhere/json/shoes', opt);


  •  

    Posting Permissions

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