I have a simple db.Model, that has one of the fields db.ListProperty(users.User)
For the REST server I used http://code.google.com/p/appengine-rest-server/
However, I can't seem to update this field..
The app is currently password-protected but if anyone wants to take a look, I can make it public.
Basically, I have a form that I post using this jQuery:
$.ajax({
contentType: 'application/json',
url: '/rest/' + $this.attr('name') + update,
type: 'POST',
data: $this.wsString(),
});
where $this.wsString() is applying serializeArray() to the form and after that transforms the result into proper REST format ( + JSON.stringify at the end ).
Here's the metadata for the entity, the "developers" field is the problematic one: http://toxik.appspot.com/Project.xml
Thanks for any help!
I managed to fix it: db.ListProperty(users.User) wants an object that serialized looks like this:
"developers":{"item":["some1#email.com","some2#email.com"]}
Related
I have a simple rails project that I've been playing around in with reactjs. To add some basic navigation, I brought the js-routes library in and it works great for urls that have a path parameter such as "localhost:3000/addresses/1".
The problem I am facing is I am trying to call a "new" resource method and it adds the (::format) literally to the url which of course bombs as localhost:3000/addresses/new(.:format) is an invalid path.
I reference the "new_address_path" path as specified in the routes-js docs. The rake output for this url is below:
new_address_path GET /addresses/new(.:format) addresses#new
The HTML snippet utilizing the above path looks like this:
<a href={Routes.new_address_path}>Create am address</a>
ENV:
-Ruby: 2.2.4
-Rails: 4.2.6
-js-routes: 1.2.8
Route in question:
resources :addresses
What am I missing here? It seems like it is not interpreting the rails route file properly.
I am not sure if I got your question. If you want to generate url with format suffix you can use format option in the helper method. For example:
Routes.new_address_path(format: 'js')
will generate something like this:
/addresses/new.js
Sorry I thought I posted my solution in here.
The problem wasn't js-routes but rather my AJAX call, I was setting the content type to JSON and I assumed that it was converting my object to JSON using the built in methods. This is not true, you need to manually convert the object to JSON via JSON.stringify(obj).
Old ajax call:
....
url: Routes.feedback_path(),
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: obj,
....
New ajax call:
....
url: Routes.feedback_path(),
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(obj),
....
You might have found a solution, but your original problem is one with js-routes, or rather your use of it.
You have to provide the parens to get the correct output from js-routes.
Original: Routes.new_address_path
Fixed: Routes.new_address_path()
As smefju posted, you can specify the format in the parens, but completely leaving them off is not an option.
I try to store the data from a graph with jQuery but I always get a 400 Bad request.
The problem is the data_series variable isnt just an array of integers but much more. This is unchangeable since it is necessary for my chart generation to be like this.
A litle piece of it to show you what I mean:
data_series[0][data][0][]:1389975624000
data_series[0][data][0][]:91
data_series[0][data][1][]:1390003200000
data_series[0][data][1][]:446
data_series[0][data][2][]:1390089600000
data_series[0][data][2][]:429
.....
My Jquery post looks like this,
$.ajax({
url: "{{ url_for('save_graph_to_session') }}",
method: "POST",
data: {
data_series: data_series
},
success: function(data) {
console.log('Saved to session')
}
});
On flask side I read it like this, and put in a session:
#app.route('/save_graph_to_session', methods=[ 'POST'])
def save_graph_to_session():
session['data_series'] = request.form['data_series'];
return "saved"
I've tried to post with 'data_series[]:' data_series, didn't work out either.
EDIT:
Maybe the solution lies within the way to request, so :
Is there a way to request in flask that ignores the fact that this is an array of arrays
this is the way one can do this:
session['data_series'] = request.form.getlist('data_series[]');
I apologize if this question seems basic as I am new to both stackoverflow and javascript in general.
My goal here is to store the user's dropdown menu selection as well as some other user inputs into variables, then I want to post the json file that contains the variables into a specific route where my serve-side javascript can read from. I have the variable part and user selection part covered, however, I am having trouble posting the variables to the specified route.
So in my app.js file in my ember framework, I tried the below code to test out if I can post {12345} to address:port/api/iwantmyjsonhere/ but when I run it and go to that specific page (address:port/api/iwantmyjsonhere/), it says cannot GET.
$(document).ready(function() {
$.ajax({ url : "/api/iwantmyjsonhere/",
type: 'POST',
dataType : "json",
data: "12345"
});
});
I understand that this question is lower level, so if you guys are too busy to answer, point me to any resources that might help me would be greatly appreciated too! Thanks in advance!
I guess this is not related to ember anywhere.
You are just using jQuery for ajax call and as per jQuery standards "Data" Object must be Key/Value pairs.
Means you should do something like -
$(document).ready(function() {
$.ajax({ url : "/api/iwantmyjsonhere/",
type: 'POST',
dataType : "json",
data: {id:"12345"}
});
});
You can read more on this one at -
http://api.jquery.com/jquery.ajax/
And if you want to implement it in ember way the you can use something like -
return Ember.$.ajax({
url: '/api',
method: 'POST',
dataType: 'json',
data: {//key value pairs}
}).then(function(result){
//After ajax is successful.
}
If I submit a form using POST, the ASP.NET server can access each value by name. However, if I do it with javascript like:
$http({
method: "POST",
url: TDSV.ROOT_PATH + "/themes/" + data.id,
params: { "xHttpMethodOverride": "PUT" },
data: { "newContent": JSON.stringify({ properties: data.json.properties, "otherInfo": "hello world" }, null, "\t") },
cache: false
});
It is all squashed together into a giant stream that I have to parse through. I have no interest in sending files this way. I just want to separate the strings by name. Is there a way to do this?
It looks like you are using WebForms, if that´s the case you must send the data in a different way.
Here is a tutorial, please take a look and let me know if that helps:
http://www.bennadel.com/blog/2615-posting-form-data-with-http-in-angularjs.htm
I currently have the following within my view
function loadData() {
var url = "/Testx.mvc/GetData";
var id = "111111";
var format = "html";
$.ajax({
url: url,
type: "POST",
dataType: format,
data: "id=" + id,
success: populateResults
});
}
function populateResults(result) {
$('#results').html(result);
}
I also have a controller called TestxController with an action method called GetData(int? id).
Now the ajax call above works on Visual Studios 2008's built-in development server, but when i switch it to use IIS webserver it doesn't. It seems like the route isn't being found because I tried putting a break point on GetData but it doesn't even reach there.
Does anyone know what i would need to do to fix this?
Edit: I've also tried the wildcard mapping method discussed at http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx and it worked perfectly. (Of course I had to remov the .mvc from the url)
Is there any way to get this to work with the .mvc extension?
Thanks
Is Testx.mvc at the root of your webserver? If your application is running in a virtual directory on IIS then the correct path would be something like /YourApp/Testx.mvc/GetData.
The Visual Studio built-in webserver might be placing Testx.mvc at root, which is why it works within VS.
If that is the case, then try using the relative path Testx.mvc/GetData rather than /Testx.mvc/GetData.
Is there an actual function called 'callback'? Just asking because it seems like you might mean to be calling 'populateResults' with a successful response.
Try this perhaps:
$.ajax({
url: url,
type: "POST",
dataType: format,
data: "id=" + id,
success: function(results){$('#results').html(result)}
});
Did you check your ISS setup to see if it supports the POST action? It might only be specifying the GET action... see http://haacked.com/images/haacked_com/WindowsLiveWriter/07de283cb368_B754/application-mappings_3.png