Hm, OK. I will try to reproduce it and check that it was not due to
something else (I give that a higher chance than dispatch not working
correctly), but I am in crunch mode for some deadlines, so I may not get
around to it until the weekend. I may misremember the URL that jQuery
created.

On Wed, Mar 9, 2016 at 11:22 AM, Jay McCarthy <jay.mccar...@gmail.com>
wrote:

> Hi Marc,
>
> If that's correct, then I think there is a problem. Here's a little
> example that shows how `dispatch-rules` should work with `request`s struct
> that have GET queries:
>
> #lang racket/base
> (require web-server/dispatch
>          web-server/http
>          net/url
>          racket/list
>          racket/promise
>          racket/match)
>
> (define-values (blog-dispatch blog-url)
>   (dispatch-rules
>    [("") list-posts]
>    [("posts" (string-arg)) review-post]
>    [("archive" (integer-arg) (integer-arg)) review-archive]
>    [else list-posts]))
>
> (define (list-posts req) `(list-posts ,@(request-bindings/raw req)))
> (define (review-post req p) `(review-post ,p))
> (define (review-archive req y m) `(review-archive ,y ,m))
>
> (define (url->request us)
>   (define uri (string->url us))
>   (define bindings-GET
>     (delay
>       (filter-map
>        (match-lambda
>          [(list-rest k v)
>           (if (and (symbol? k) (string? v))
>               (make-binding:form (string->bytes/utf-8 (symbol->string k))
>                                  (string->bytes/utf-8 v))
>               #f)])
>        (url-query uri))))
>   (make-request #"GET" uri empty
>                 bindings-GET #f "1.2.3.4" 80 "4.3.2.1"))
>
> (blog-dispatch
>  (url->request "http://www.chrlsnchrg.com?data=value";))
>
> --
>
> From the perspective of the HTTP library, the ? part is *not* in the URL,
> so if you are seeing it there for dispatch-rules, then there's a problem.
>
> Jay
>
>
> On Wed, Mar 9, 2016 at 11:13 AM, Marc Kaufmann <marc.kaufman...@gmail.com>
> wrote:
>
>> Oh, in this case the reason for wanting other separators, namely the ?
>> used automatically by jQuery's ajax functions. When I use $.get (from
>> jQuery), it adds whatever data I want to send automatically by appending a
>> bunch of ?data1=value1 and so on. That's the only reason for wanting to
>> split the URL by different patterns - or alternatively, to ignore any URL
>> ending in such values. (Maybe that wasn't clear, but a url
>> my-great-website.com?data1=value1 does not work when dispatch is looking
>> for my-great-website.com only. That was really the problem I tried to
>> solve - to let it go through and ignore the end.)
>>
>> That's why I switched to $.post, which doesn't affect the URL that is
>> sent.
>>
>> On Wed, Mar 9, 2016 at 11:05 AM, Jay McCarthy <jay.mccar...@gmail.com>
>> wrote:
>>
>>> On Sat, Feb 27, 2016 at 5:38 PM, Marc Kaufmann <
>>> marc.kaufman...@gmail.com> wrote:
>>>
>>>> As we are on it, is there a way to have `dispatch-rules work on url's
>>>> with regular expressions, so that it would work on ajax1, ajax2, etc, or
>>>> would I have to create my own bi-directional match-expander for that? (I
>>>> haven't tried to figure out how that would work though.) The reason I ask
>>>> is that when sending bindings in the url,  'dispatch-rules chokes, since
>>>> the url looks different. An alternative is to use continuations, and pass
>>>> the url for the continuation into javascript.
>>>>
>>>
>>> There is no regular expression bidi-matcher, but you could make one.
>>> You'd have to make the to-url side take in a string and check that it
>>> matches the regexp. However, I'm a little skeptical. What's wrong with
>>> using strings, numbers, etc? You just don't want to have /s separate the
>>> pieces, you want some other character to separate the pieces in the
>>> encoding?
>>>
>>> Jay
>>>
>>>
>>>>
>>>> On Sat, Feb 27, 2016 at 3:04 PM, Jay McCarthy <jay.mccar...@gmail.com>
>>>> wrote:
>>>>
>>>>> Hi Marc,
>>>>>
>>>>> Each `dispatch-rules` rule takes a keyword option for which methods
>>>>> you want it to handle, the default being no method and "get". So your
>>>>> call is equivalent to
>>>>>
>>>>> [("test-ajax") #:method "get" ajax]
>>>>>
>>>>> but you want
>>>>>
>>>>> [("test-ajax") #:method "put" ajax]
>>>>>
>>>>> This facilitates more easily having different functions for different
>>>>> methods.
>>>>>
>>>>> Jay
>>>>>
>>>>>
>>>>> On Sat, Feb 27, 2016 at 1:03 PM, Marc Kaufmann
>>>>> <marc.kaufman...@gmail.com> wrote:
>>>>> > Hi all,
>>>>> >
>>>>> > I perform the following call in jQuery in a page:
>>>>> >
>>>>> >         $.post( "test-ajax",
>>>>> >                 function( data ) {
>>>>> >                     alert( "Data Loaded: " + data);
>>>>> >                 });
>>>>> >
>>>>> >
>>>>> > The test-ajax page gets called via the url-dispatcher:
>>>>> >
>>>>> >   (define-values (site-dispatch site-url)
>>>>> >                  (dispatch-rules
>>>>> >                    ...
>>>>> >                    [("test-ajax") ajax]))
>>>>> >
>>>>> > and the ajax function is simply this:
>>>>> >
>>>>> >   (define (ajax req)
>>>>> >     (response/xexpr
>>>>> >         "1 "))
>>>>> >
>>>>> > Nonetheless, the above Ajax call fails with a 404 error, but when I
>>>>> replace
>>>>> > $.post by $.get, it works. As far as I can tell, the only thing
>>>>> about the
>>>>> > request this changes it the method, from POST to GET.
>>>>> >
>>>>> > Is there a reason this fails? Do I need to tell the webserver that
>>>>> it should
>>>>> > serve both POST and GET?
>>>>> >
>>>>> > Btw, the reason I want to use post is that when I use get, the data
>>>>> I send
>>>>> > with the request gets put at the end of the url
>>>>> (../test-ajax?some-binding)
>>>>> > and I couldn't figure out how to have the dispatcher deal with this
>>>>> problem
>>>>> > (that returned an error 500).
>>>>> >
>>>>> > Thanks,
>>>>> >
>>>>> > Marc
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> > --
>>>>> > You received this message because you are subscribed to the Google
>>>>> Groups
>>>>> > "Racket Users" group.
>>>>> > To unsubscribe from this group and stop receiving emails from it,
>>>>> send an
>>>>> > email to racket-users+unsubscr...@googlegroups.com.
>>>>> > For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Jay McCarthy
>>>>> Associate Professor
>>>>> PLT @ CS @ UMass Lowell
>>>>> http://jeapostrophe.github.io
>>>>>
>>>>>            "Wherefore, be not weary in well-doing,
>>>>>       for ye are laying the foundation of a great work.
>>>>> And out of small things proceedeth that which is great."
>>>>>                           - D&C 64:33
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Jay McCarthy
>>> Associate Professor
>>> PLT @ CS @ UMass Lowell
>>> http://jeapostrophe.github.io
>>>
>>>            "Wherefore, be not weary in well-doing,
>>>       for ye are laying the foundation of a great work.
>>> And out of small things proceedeth that which is great."
>>>                           - D&C 64:33
>>>
>>
>>
>
>
> --
> Jay McCarthy
> Associate Professor
> PLT @ CS @ UMass Lowell
> http://jeapostrophe.github.io
>
>            "Wherefore, be not weary in well-doing,
>       for ye are laying the foundation of a great work.
> And out of small things proceedeth that which is great."
>                           - D&C 64:33
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to