Reputation: 155
I can do it the other way, but now i need to send a request from the server, to avoid setting up a timer to check something every 100 milliseconds or so, instead i could just send a request FROM Pyramid to the website. So far i tried this but no luck:
The View i created to hold the request:
@view_config(route_name='request', request_method="POST")
def request(self):
sometext = "Some random text"
return Response(sometext)
Ajax:
function getmsg() {
$.ajax({
type:"GET",
url:"/req", // Route for the View
dataType: "text"
success:function(result){
alert( result );
}
});
The request is just simply not sent! any help would be appreciated!
Upvotes: 0
Views: 253
Reputation: 8809
Right to clear everything up...
If you want to make an AJAX request from within a pyramid view, you will not need to use the pyramid framework code to do this, rather generic python, take a look at the requests library...
See the below question/answer on how to achieve this:
AJAX request with python requests library
As per your question, this will let you send a ajax request FROM the server (aka pyramid) to any other server.
Upvotes: 0
Reputation: 7613
You are sending a "GET" request from Ajax but looking for a "POST" request in pyramid. Change your Ajax type to POST or remove the request_method in your @view_config params(this will accept either posts or gets.
Upvotes: 0
Reputation: 18060
You can't "POST" from the server. That's not a Pyramid limitation, that's how HTTP is (a client makes a request to a server).
There are a few ways to send data from the back-end to the front-end like you want:
Upvotes: 2