I am using Javascript MVC models separately from JMVC (just as a jquery plugin).
Everything works fine, instead of overriding REST URLs. Look:
I am trying to override URL to retrieve data from server.
But it still tries to load data from URL "/Tags.json" instead of "/t.json".
$.Model.extend("Tag",
{
findAll: "/t.json" //overriding URL for findAll (just like in the manual)
});
$(function(){
Tag.findAll({}); //loads '/Tags.json' instead of 't.json'
})
Is it a bug?
$.Model("Tag",{
findAll : "/t.json"
},{})
You need to call $.Model not $.Model.extend
.findAll docs
Related
Can I dynamically edit the url of the datatable depending on the value of the “Value” field of the search form in another file?
For example:
{ view:"text", label:"input data", value:"apple" }
In datatable.js
url: 'resource->/api/archive/apple'
Okay, I was told that I can send AJAX requests, but now I can't figure out how to get them correctly on another page
Sending:
webix.ajax().post('apples', get_form())
routie('apples')
In devtools I get the form value
I'm trying to get the formData value to substitute it in the URL
function get_data() {
let result;
webix.ajax("apples").then(function (data) {
data = data.text();
result = data;
});
return result;
}
URL
url: 'resource->/api/archive/all/'.concat(get_data()),
On the backend side, this controller works well, but I can't call it from the front side. I'm just learning frontend, so any help would be greatly appreciated.
In general, the way to do this is: When the value is changed (the onChange event), call clearAll() and load(newUrl) methods of the datatable. You cannot change the url property at runtime (well, you can, but it won't work).
As for different files, people usually build SPAs with Webix, so files here might be modules, not pages. Do you use Webix Jet? If yes, then communication between the form and the datatable can be done via the app event bus. If not, then they can communicate directly (import both files in some other file and do it there). If this is a multiple-page app, then yes, you do need some server side communication between them (maybe even with sockets).
I'm quite new to JavaScript and Node JS and I have a such a situation. When I try to call get of express.js with a single parameter everything works fine, but when I try to call get with more than one parameter, it trims the query.
For example I have such call and function
app.get('path/data', myFunc);
// in another file
function myFunc(req, res) {
// do some stuff
}
When the url is path/data?id=5 or path/data?name=foo everything is fine. But when I use for example url like path/data?id=5&name=foo in myFunc I get url as path/data?id=5. So I get url's first part - what is before & sign.
Now what am I doing wrong? Is there something that I'm missing? How can I get whole url in myFunc without being trimmed?
Use
app.get('path/data?:id?:name')
And for retrieving the values, use req.query.id and req.query.name.
For accessing the REST api, you need to hit:
http://localhost:8080/demo?id=3&name=stack
So, by this you can add multiple parameters in your api.
Hope this helps.
I found the problem. I was requesting via curl and it turns out that shell command trims in case of there is an & in the url. So there is a need no add quotes like this
curl "path/data?id=5&name=foo"
I want to pass a parameter to my Store proxy to retrieve the right data from the server. I need to pass the parameter without the name prefix and just the value.
Instead of this kind of url :
myAppUrl/collections/units?collectionId=54
which can be done like this:
myStore.getProxy().extraParams.collectionId = 54;
I want to have a call like this:
myAppUrl/collections/54/units
My web service is adapted for both calls I just need the correct client code to pass the parameter.
Please help and advise.
An old question, but I write for anyone with this problem. I implemented the idea of #Saki in this package (for ExtJS 6) because of my own needs:
https://bitbucket.org/alfonsonishikawa/extjspackages/wiki/Server%20URL%20Placeholders
The idea is being able to use an URL like:
proxy: {
type: 'rest',
url: 'myAppUrl/collections/${collectionId}/units',
appendId: false
}
With that package, you just have to configure your proxy like above and call #load() with params:
store.load({
params: {
collectionId: 54
}
});
(getProxy().extraParams can be used as default value)
This is the source code as example that you asked #Saki about.
It looks almost like REST request but not exactly as REST places indexes at the end of url. You could solve it by implementing a custom buildUrl of Ajax or Rest proxy. In any case, see how is this method implemented in Rest proxy.
you can set your url dynamically and then call load method of store using below code.
store.getProxy().setUrl('your new url');
store.load();
but if you gonna use this method then you have to set correct url every time other-vice may be you will get wrong data.
I am new to Dojo Framework.I created one button using dojo constructor and dojo.connect onclick event function i written url and load functions.This url navigating servlet and get the response back.
but i don't want response back i want to send request only.
how to do this..anyone help me.
thanks in advance.
are you looking to navigate to another page? if so, you can use window.location.href or other approaches to achieve that. See the foll url for other approaches:
JavaScript: Navigate to a new URL without replacing the current page in the history (not window.location)
if you do not want to navigate but just send some data to the server (and dont care about the response), you can just write an empty function for the callback
var deferred = dojo.xhrGet( {
url : "xxx",
load: function(data) {
//ignore
}
});
});
However, it is recommended to always check the response to ensure there were no errors on the server side.
You could also use dojo.xhrPost to submit your form
I have built a calendar in php. It currently can be controlled by GET values from the URL. Now I want the calendar to be managed and displayed using AJAX instead. So that the page not need to be reloaded.
How do I do this best with AJAX? More specifically, I wonder how I do with all GET values? There are quite a few. The only solution I find out is that each link in the calendar must have an onclick-statement to a great many attributes (the GET attributes)? Feels like the wrong way.
Please help me.
Edit: How should this code be changed to work out?
$('a.cal_update').bind("click", function ()
{
event.preventDefault();
update_url = $(this).attr("href");
$.ajax({
type : "GET"
, dataType : 'json'
, url : update_url
, async : false
, success : function(data)
{
$('#calendar').html(data.html);
}
});
return false;
});
Keep the existing links and forms, build on things that work
You have existing views of the data. Keep the same data but add additional views that provide it in a clean data format (such as JSON) instead of a document format (like HTML). Add a query string parameter or HTTP header that you use to decide which view to return.
Use a library (such as YUI 3, jQuery, etc) to bind event handlers to your existing links and forms to override the normal activation functionality and replace it with an Ajax call to the alternative view.
Use pushState to keep your URLs bookmarkable.
You can return a JSON string from the server and handle it with Ajax on the client side.