Thank you for the reply.
I am using url_dispatch.
I have done as follows:
In the init.py: I have added:
config.add_route('ajax', '/ajax/', view='testproject.views.ajax')
In the views.py:
def ajax(request):
string = 'hello world'
return Response(string)
and my jquery code:
$("a#button").click(function(){
$.post("/ajax/", {}, function(data) {
$("div.data_container").html(data);
}, "text");
});
Okay, so this works, but am I setting up the view and add_route
correctly. Is this how it is suppose to be done?
Thanks.
Awais,
On Jun 16, 2:21 pm, Robert Jackiewicz <[email protected]> wrote:
> Hi AwaisMuzaffar,
>
> 1. To be able to call a python function via an ajax call you will have to
> make the function in your python module a callable view and then call the url
> that is assigned to the view in your js script.
>
> 2. As for calling a view in $.post, are you using traversal or url_dispatch?
> Using either system would cause the urls to be slightly different. The
> simplest route to take is using url dispatch since it would allow you to
> create a simple url like /aview/.
>
> If you have any other questions please let me know.
>
> Cheers,
>
> RJ
>
> On 2011-06-16, at 8:18 AM, AwaisMuzaffar wrote:
>
>
>
>
>
>
>
> > 1- In my pyramid package directory, if I create a file called
> > somefunction.py and I want to call this function using $.post, what
> > URL would I specify to call this function.
>
> > and:
>
> > 2- And if I have a view function called aview created in views.py, can
> > I call this function by simply referring the $.post URL as /aview/
>
> > (script files reside in the static folder)
>
> > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "pylons-discuss" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/pylons-discuss?hl=en.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.