Reputation: 4564
I have a small server running on localhost:8083
I tested a put
request with Chrome postman client
http://localhost:8083/addcompany?{"Ticker":"Hello", "Name":"Hello, Inc."}
which translates in
POST /addcompany?{"Ticker":"Hello", "Name":"Hello, Inc."} HTTP/1.1
Host: localhost:8083
Cache-Control: no-cache
and correctly returns:
{
"Ticker": "Hello",
"Name": "Hello, Inc."
}
I have tried to implement the same request in my client app.
postTicker = (tkr, name) ->
console.log "posting #{tkr}, #{name}"
aCompany = JSON.stringify ({Ticker:tkr, Name: name})
console.log aCompany
queryUrl = encodeURI 'http://localhost:8083/addcompany'
$.ajax queryUrl,
type: 'POST'
timeout: 5000
data: aCompany
success: (response) ->
#parsedResponse = $.parseJSON response
alert response
#removeAddBtn (parsedResponse.ticker)
error: (response) ->
console.log "AJAX Error: #{response}"
The request results in the error message:
Uncaught TypeError: string is not a function
for data: aCompany
.
Upvotes: 0
Views: 503
Reputation: 780
I believe you don't need to stringify your data. Could you try to change the third line of your javascript:
from:
aCompany = JSON.stringify ({Ticker:tkr, Name: name})
to:
aCompany = {Ticker: tkr, Name: name}
Upvotes: 1