I am very much new to CRM, I got a requirement, asking me to create a simple accordion with name and status - as panel heading. And after expanding the panel, I should give all the details about the user details in the entity. All the details will be fetched dynamically from the back end. Can some one help me in writing this. I don't know how to start. everything will be dynamic, depends on the field in the DB. Hope I explained clearly
First of all you should design a accordion or dropdown-toggle etc with html, css and JavaScript . Second you should call Ajax to fetch data from back-end then back-end gonna return a JSON. After that you should assign values to their own places. The code below is a sample for calling an Ajax with JQuery:
var parameters = {id:10};
$.ajax({
type: "POST",
data: parameters,
datatype: "json",
url: '#Url.Action("ProductList", "Product")',
success: function(result){
$("#username").attr('value', result.Username);
}
Related
This is my first time attempting filtering and searching the mySQL database. From my research I have found out I need an AJAX call and some PHP query that will help my achieve the filtering I want to achieve.
This is what I want the AJAX search to do:
Have an Apply button. When I click the button I want a URL to get generated and the AJAX call to happen.
Only reload part of the page where the data queried is contented.
So far I have managed to create this:
$("#filteridname").change(function() {
$value=$(this).val();
$.ajax({
type: "get",
url: "{{$myurl}}",
data: {'search':$value},
success: function(data){
$('#data-holder').html(data);
}
});
});
This manages to create the URL one of the filters, but it does not take the other filters into consideration. I also did not manage to create the button. I am guessing you would need a where statement in the PHP to filter the database?
Would anyone be willing to assist me in creating the AJAX call and PHP query for the filters?
In total I have three filters, and when I click a button I want an AJAX call to filter my database with the three filters and return the results without having to reload the whole webpage.
EDIT: Here is my JS AJAX query:
$("#apply").click(function() {
$country=$('#filter-country').val();
$type=$('#filter-type').val();
$year=$('#filter-year').val();
$.ajax({
type: "GET",
url: "{{$launchsitename->site_code}}",
data: {'country':$country, 'type':$type, 'year':$year},
success: function(data) {
$('#data-holder').append(data);
}
});
});
Now I just need to create a PHP query.
you can use propriety called .Append() instead of .html() ,also here you are getting one element value on change , if you want to get the three of them at one button click , you can make it the same way that you got the val of the first one , and just adding it to the request and handle it back in PHP to divide and execute each one or just pass the three of them to your procedure , depends on what you have
$("#filteridname").change(function() {
$value=$(this).val();
$.ajax({
type: "get",
url: "{{$myurl}}",
data: {'search':$value},
success: function(response){
$('#data-holder').append(response);
}
});
});
Read about .append()
I have a simple table with records and each of them has a btn with data-id attribute to run the confirmation dialog:
#foreach (var dog in Model)
{
<tr>
<td>#dog.Name</td>
<td>#dog.Age</td>
<td>Delete</td>
</tr>
}
After clicking the delete btn, this code is running :
$('.deleteBtn').on('click', function () {
$.ajax({
url: '#Url.Action("DeleteConfirm", "Home")',
data: {
id : $(this).attr('data-id')
},
success: function(data)
{
$('#myModal').empty().html(data).modal('show');
}
});
});
As you can see, its Ajax request to my Action in HomeController. It returns PartialView that is loaded to my Bootstrap dialog:
<div class="modal fade" id="myModal">
</div>
After showing the dialog, the user can click confirm to delete the row via button with class saveBtn. Thats what happens after I click it :
$('#myModal').on('click', '.saveBtn', function () {
var numer = $(this).attr('data-id');
$.ajax({
url: '#Url.Action("DeleteDog", "Home")',
type: 'POST',
dataType: 'JSON',
data: {
id: numer
},
success: function (data)
{
if (data = 'true')
$('a[data-id=' + numer + ']').closest('tr').remove();
}
});
});
So as you can see there is another Ajax (POST this time) request to delete the row.
So here is my question. Is this approach good practice? I'm not sure because in order to delete a row i have to send 2 ajax request (to load confirm dialog, and delete after confirm). Can anyone experience developer comment this code and say whether im doing it good or bad? I would be grateful.
It's always a good idea to challenge whether or not you could do things more effectively (as you have here.) So, let's think about it...
The Question:
Is it a good approach to send to two ajax requests - one to load a partial view and the second to post a delete request from the partial - for a single "user action"?
The Answer:
Maybe.
Why?
Based your example, if your goal is to simply confirm with the user whether or not they want to "Delete Dog ID: foo?" You can absolutely do that without making a trip to the server for a partial view. Presumably, in your first ajax call - $(this).attr('data-id'); - is the dog's Id. You already have it!
In most circumstances, when you make a get request with an identifier, like /dogs/id?='foo' you're using foo to access some additional information about the object from a persistent data store. Like, for example, the dog's owners, similar dog breeds, last visit to the vet, etc.
If additional information about the dog (owners, other dogs, vet) is an important part of deciding whether or not to delete the dog AND there's a good reason not to load it when the page loads intially then it totally makes sense to issue two ajax calls.
It could also make sense to issue two ajax calls just to get the partial view html, even if you don't need additional "dog" data, if you simply don't want the "parent" page to be to big (hence, slowing it's loading time.)
Ultimately, though if you're not retrieving additional data, and there's no specific reason to load additional html, it's probably best in this case to just update the modal dialog using javascript/jquery:
Example fiddle
I am trying to make an online shop that allow users to spend minimum time on checkout.
They have to select from 4 possibilities which i can make it two ways.
First i can make a select field with jquery to update the next fields from database or i can make 4 tabs and each of them have diferent forms that take data from database.
Bassicaly i want to ask what should i choose and i don't really know how to do it with jquery so if you suggest that way please post a tutorial if available cause i didn't found one related to updating select fields from database.
Second i need to know if choosing the tabs should cause any problem of security on posting form or something like that.
i use CI2.
Thank you in advance.
Thats true, sorry. Here a code fragment from one of my projects
$('select.myfield').change(function(){
var data = $('select.myfield').val();
$.ajax({
url: 'Url/to/your/script',
dataType: 'json',
type: 'post',
data: data,
success: function(data) {
//validate
//change form fields
}
});
});
in your PHP method, you need return json_encode($data);
Currently, I have a mySQL database setup as follows:
fullname
address
cellphone
homephone
email
It is for users registering for my company. In the employee section of the site, there is a drop down menu, which is populated from the fullname row of the database. Is there a way using JavaScript/AJAX to display the entire column of data, based on the person currently selected in the drop down menu?
As pimvdb and myself stated, you will require a server-side language to accomplish this.
Yes there is a way.
Look into jQuery
http://jquery.com/ where you can create element.
Use ASP.NET to read the data from the SQL server, then make a jQuery AJAX call to your ASP.NET page, and finally display it.
Here is a snippet from my code, that should help you out.
$.ajax({
type: "POST",
url: "YOURPAGE.aspx/YOURMETHOD",
contentType: "application/json; charset=utf-8",
data: "{ 'upc':'" + value + "' }",
dataType: "json",
success: function (result) {
var yourelement = document.getElementById("someelement").options;
//mess around with the element here
}
},
error: function(){}
});
It's easy with AJAX. Just have a page that prints the resultset formatted however you like. Then do a simple jQuery call like:
$("#personDiv").load("person.php?name="+$("#fullname").val());
i highly recommend the use of jQuery and the use of .ajax()
I'm trying to save dynamically created elements in my application.js file to the database. Would the code look something like this?:
$.ajax({
type: "POST",
data: { title: 'oembed.title', thumbnail_url: 'oembed.thumbnail_url'}
});
Is there anything I'm missing? Assume that oembed.title and oembed.thubnail_url hold the values I want to save, and that title and thumbnail are the database columns.
First problem I see is your data is strings. Get rid of the ' quotes
$.ajax({
type: "POST",
data: { title: oembed.title, thumbnail_url: oembed.thumbnail_url}
});
I'm going to assume you need to incorporate some user-supplied data into the new DB object - otherwise, it would be way easier to just create it from Rails.
If you're using entirely user-supplied data, you can use the serialize() method (use hidden fields for server-generated stuff):
jQuery.ajax({
url: '/path/to/whatever',
data: $('#MyForm').serialize(),
type: 'POST'
});
Or you could use the jQuery Form Plugin - it'll let you easily combine user-supplied data with server-generated data. For example:
$('#MyForm').ajaxForm({
//Hardcoded/server-generated stuff goes in here
//(and will be added to the data from the form inputs):
data: {title: oembed.title},
type: 'POST'
});
The ajaxForm() function will set up the form and its defaults, and sends an AJAX call when the user hits the submit button (see also: ajaxSubmit()).
On the Rails side, everything should work exactly the same as if the user had submitted the form normally (though you might want to just respond with a status code/message - no call for a redirect or page render).
Hope this helps!
PS: From your example, it looks like you might be able to use data: oembed in your AJAX calls. This will submit all oembed's attributes...