I want to send checked values to server.
The checkboxes are categorized by three category
1. name= fields
2. name= tasktypes
3. name= lifestyles
I success to get checked values each of category
and save the values to list named fileds, tasktypes, lifestyles.
when I send this lists to server,
$ajax. is not a function error occured.
and error: define is not work.
what is the reason?
and how can I debug this ajax module?
Related
I am using datatable with Laravel to order a response that i receive from an API
I connect to the API with this code:
$ch = curl_init('https://api.turn14.com/v1/items?page=$page');
How you can see i just need to add the $page and it starts to take me all the products from their page, if i add page=1 it takes all the values of the API from the page 1, etc etc
The thing is that I am using datatable server side because i want to use all the functionalities that it offers me BUT I do not know how can i pass the number page with the datatable, I mean if I push the number 2 in the button how can i get that value?
I mean in the paginator says 1 .. 2 .. 3 etc, if i push 2 how can i know that i pushed in the button 2?
Thanks!
It would be good to know more about your code. That said, from what I can understand, when you pass the page number to the url - you receive the next page with data from the endpoint. If you are using the Laravel paginator and not something custom, the usual way it works is that it appends a query parameter to the current url:
Imagine you have a controller HomeController with a method index:
use Illuminate\Http\Request;
public function index(Request $request) {
dd($request->get('page')); // this will return your current page
// Make sure you check the page query parameter first before using it like this.
$ch = curl_init('https://api.turn14.com/v1/items?page='.$request->get('page'));
return view('home');
}
For more information you can read the Laravel docs:
https://laravel.com/docs/5.8/pagination#basic-usage
By default, the current page is detected by the value of the page query string argument on the HTTP request. This value is automatically detected by Laravel, and is also automatically inserted into links generated by the paginator.
I have a form with method="get" set on the form. I have a control (DropDownList) with the SelectMethod attribute defined to populate the list's contents. On first load the SelectMethod is called and works (and I can verify this with a breakpoint). However, if I submit the form I can see the browser update and the query string get populated but SelectMethod is not called/I don't hit the breakpoint.
I'm more or less following the example from Microsoft here http://www.asp.net/web-forms/overview/presenting-and-managing-data/model-binding/using-query-string-values-to-retrieve-data
only I'm using a form submission with a GET instead of a link with a mutated query string.
Let me tel the scenario where I am stuck, I will try to explain simply rather than telling the actual.
1st : I am on page 1. Where few subjects are there with unique names.
2nd : I will click on one subject, which will call an struts2 action (lets call it ActionA)at back end with the unique subject name as a request parameter(Request type = GET).
3rd : Action A will only redirect to "Tutorial page".
4th : While loading it will make an AJAX call to another Struts2 action (lets call it ActionB), which will return JSON containing tutorials for that Subject.
Problem: As I am calling ActionA first and passing the subject name which is just redirecting the page to some other page. On page load I am calling another action to get the JSON. I am not able to get the request parameter value at ActionB that is the one which is returning JSON.
Note: I am using Struts2-JSON plugin thats why not need two actions, one for redirecting the page another for getting the JSON at page load.
Solution tried: I have tried to get the request parameter value that is the Subject name, putting a hidden field in the Tutorial page. But unable to get the value from inside the Angular JS controller.
Here is the example for a shared Service: http://plnkr.co/edit/P2ItVj20RYCJVjdIaXfY
But you are right if you reload the page this doesn't work. I think your scenario needs tweaking if you want to use angular or any other single page framework for that matter. One purpose of single page applications is to minimize reloads, preferable none. If your action A only returns a template where you then want to input the result of action B, I recommend looking at ngRoute or uiRouter, where you define a template (result of action A) and a controller for that view. This template than replaces a section of your page (ng-view) with the new template. If both are new to you I would recommend looking at uiRouter, it is similar but it gives you a lot more possibilities. Both provide a "resolve" function where you can load your action B before the page is rendered.
Code from plunker
angular.module("app", [])
.controller("MainController", ['SharedService', function(SharedService) {
var vm = this;
//bind to service
vm.service = SharedService;
}]);
Service
angular.module("app")
.factory("SharedService", [function() {
var service = {
id: "test"
}
return service;
}]);
I have a form with a number of fields.
Some of them are userId, userFirstName, userLastName.
When user inputs incorrect userId value then near userId field page must show error message and add this error into validationSummary(this is standart behavior for asp.net mvc unobtrusive validation). If userId is correct then page must remove errors and autopopulate userFirstName and userLastName(This is not standart behavior)
How can i implement this?
Here is what come to my mind:
Remote validation attribute
It has a bad customization in my case. That's why i decide to don't use it.
Add special method for jquery validation plugin ( for example
jQuery.validator.addMethod("userIdValidation", function(value, element) {
//some logic
return something;
}, "Please specify the correct userId"); )
and put there logic for validation and for autopopulate other fields.
In this case i mix validation and other stuff.
3 . Add special method for jquery validation plugin ONLY for validation and add special handler for input change event for autopopulate.
In this case i need to send TWO ajax requests to server for one thing. And ofcourse it is not good too. So what is the right way? I am confused.
Have you thought about using a partial view to display the userFirstName and userLastName?
You can fire an AJAX request that sends the userId, and then returns a partial view of the name fields. Within the controller being called, you can validate the incoming userId, and then grab the name details in one query. If thevalidation fails, you can return the partial view with empty fields.
Lets say I have couple of filters in my deployment descriptor and each request to the app has to pass through those. There is form with a formbean attached to it. Once I fill the form and click submit, when does the html parameters in the form are binded to the form bean? Before the request is passed through the filters or after passing thorugh the filters?
The reason I am asking is.. I have a form with 20 fields. Once I click submit, 17 values are being binded to the bean properly but 3 values are missing by the team request reaches validate method. I am absolutely clueless has to where the values are missing. I tried to print an enumeration of all the request parameters in validate method and those three fields are there in request object. AFAIK, There is no issue with those three elements name because the app works perfecly in my local IDE but brakes up in test env which makes it all the more difficult to pin-point the issue :(.