I am using jQuery dataTables verion 1.9.4 and spring MVC. I want to pass encoded parameters to controller using aoData.push method. I have used :
aoData.push({"name":"message", "value":encodeURIComponent("test Message")})
.. But in the controller I am receiving test%20message instead test message. Is there any way to decode the dataTable parameters in controller like filters?
Any help or guidance would be appreciated.
You can try this:
nServerParams": function (aoData) {
aoData.push({ "name": "message", "value": encodeURIComponent("test
Message").replace(" ", "%20")});
},
Related
I'm trying to get WordPress website title using javascript and WP API plugin
I didn't find any example on how to get the site's name but I found the variable name under the entities section in the developer guide
function _updateTitle(documentTitle) {
document.querySelector('title').innerHTML =
documentTitle + ' | '+ $http.get('wp-json/name');
}
The output string of $http.get('wp-json/name') is [object Object]
Does anyone know how to use fix this?
You didn't get enough context. What's $http? What happens when you go to wp-json/name directly in your browser? Here's what I see:
[{
"code":"json_no_route",
"message":"No route was found matching the URL and request method"
}]
Here's a simple example to get you the title:
var siteName;
$.getJSON( "/wp-json", function( data ) {
siteName = data.name;
});
See more elegant solution here https://wordpress.stackexchange.com/a/314767/94636
response will not contain extra data like:
authentication: []
namespaces: ["oembed/1.0", "akismet/v1", "acf/v3", "wp/v2"]
routes: {/: {namespace: "", methods: ["GET"],…},…}
timezone_string: ""
...
_links: {help: [{href: "http://v2.wp-api.org/"}]}
i followed this to learn how ODataController works, everything is OK but when i changed the request uri
from
"localhost:49292/odata/Employees" //result: 200
to
"localhost:49292/odata/employees" //result: 404
to say one word: "odata" or "Odata" and "Employee" are all ok, but lowercase "employee" return 404. any explanation about this. Moreover, the routes in asp.net mvc is not case-sensitive afaik.
how about including a Route attribute and direct it to lower case. for Upper case web api will take care about it
[Route("odata/employees")]
add this on the top of the controller
if odata is common for every action then you can include [RoutePrefix] attribute
You can manually do it using the ODataModelBuilder instead of the ODataConventionModelBuilder
e.g
var builder = new ODataModelBuilder();
builder.EntitySet<Order>("Employees");
builder.EntitySet<Order>("employees");
this will work but your metadata will show 2 entity sets:
{
#odata.context: "http://localhost:62881/$metadata",
value: [
{
name: "Employees",
kind: "EntitySet",
url: "Employees"
},
{
name: "employees",
kind: "EntitySet",
url: "employees"
}
]
}
lowercase "employee" return 404.
I hope you probably didn't have the typo like that.
AFAIK, there is a case limitation on filter and properties. (You can vote there https://aspnetwebstack.codeplex.com/workitem/366 ) but not sure about the controller name..
You can create the REST server using web api without having oData as well..
I have a controller in my Rest API that expects an array of json (in POST)
{
data: [
{
name: "marc"
},
{
name: "john"
}
]
}
Submitted data are then saved in database.
I don't know what annotation to use in order to tell "nelmio api doc bundle" to generate the appropriate html page in order to have capability to test my API by creating multiple items (an array of items).
To resume the question is : Can nelmio documentation generates a dynamic collection of forms ?
You can test your API through nelmio sandbox.
Nelmio have the "New Parameter" button which is can add multiple key => value parameters.
basically I am trying to integrate the thrid party api in symfony2 application. I have the php class from api documention. I want integrate that in my custom bundle controller.
I also looking to add the option to configure the api key and secrets. I don't know how to start. Please look at below that i want to do
Example:-
namespace Acme\DemoBundle\Controller;
class DemoController extends Controller
{
public function indexAction()
{
$myApi = new MyApi($key,$secret); // this is the stuff, I am trying to do!
return array();
}
}
First I try to create the library format symfony package. I don't know how to achive this this type. Can Some one tell me what are thinks I need to do.
TO do this in a proper way, you have to declare you api class as a service & use dependancy injection to inject your parameters :
parameters:
your_api.class: Acme\HelloBundle\Lib\YourApiClass
your_api.key: "key value for your api"
your_api.token: "token value for your api"
services:
yourApiService:
class: "%your_api.class%"
arguments: ["%your_api.key%", "%your_api.token%"]
And in your controller & many other places you'll have access like that :
$api = $this->get('yourApiService');
Take a look for more informations : http://symfony.com/doc/current/book/service_container.html
you can use it as a service:
http://symfony.com/doc/current/book/service_container.html
when i try to implement an extern api, i think about adapter pattern:
http://en.wikipedia.org/wiki/Adapter_pattern
I'm building a dynamic ExtJS form based on JSON data loaded from an ASP.NET web service. The problem I find is that ExtJS expects the JSON in a specific format, ie.
{ "metaData": { "title": "Testing" }, "data": [], "success": true }
When using an ASP.NET web service to return an object as JSON it returns with the first element "d", ie.
{ "d": { "metaData": { "title": "Testing" }, "data": [], "success": true } }
Is it possible to tell the ExtJS form to use "d" as the root node?
After some more testing I've found that the ExtJS form does load the JSON from my web service but because the response text doesn't have "success": true in the root it is handled by the 'failed' handler. Fortunately this handler accepts the same parameters as the 'success' handler so can be manipulated the same.
Here's an example of my form load handler:
this.form.load({
url: "myservice.asmx/getUser",
headers: {'Content-Type': 'application/json'},
success: function(form, action) {
//not fired
},
failure: function(form, action){
if (action.result.d){
//process data
}
}
});
You don't have to call form.load() of course. I bypass it, and simply call my ASMX web method directly by calling the AJAX function that links to my webmethod, as provided by the ScriptManager. MS AJAX does all the JSON decoding, and factors out the 'd' property, etc.
Your web method doesn't even have to return an object with the 'success' and 'data' objects, as required by form.load(), although it's a useful format and I stick to it.
With the 'data' object returned by the web method (with name/value pairs, where name == field name) you can now call ExtJs's form.setValues(data); to write the values into the fields.
This is a perfectly valid case for bypassing ExtJS's code.
--
As with loading, so with submitting. To get around the 'd' property problem in the object that has to be returned by the submission web method, handle the click event of the Submit button, and push the data to the server by directly calling your web method. Your web method can/should return an object in the same format as is required by ExtJs. But you get back this object, and if not successful, call form.markInvalid() yourself, passing in the 'errors' property. Peasy easy and works well.
Again, since ExtJs doesn't play nice with the 'd' property it's perfectly valid to bypass it and do things yourself.
--
I tend to use the ScriptManager-provided functions for calling my web methods more and more, and bypass ExtJs's AJAX method invoking code. The former are much simpler to use, know about the 'd' property and also know how to deserialize Microsoft's JSON format for serialized DateTime objects.