jquery form submit action doesn't work on document.ready - html

I have this jQuery code:
$(document).ready(function() {
$.ajax({
url: "pages/"+page+".php",
cache: false
}).done(function( html ) {
$('#main').html(html).css({"max-height":mH-30,"height":mH-30}).jScrollPane();
$('form').not('#loginf').submit(function(event) {
event.preventDefault();
var inputs = $(this).serialize();
$.ajax({
url: "pages/"+page+".php?"+inputs+'&action='+param,
cache: false
}).done(function( html ) {
update(html);
rs();
}).fail(function (){
window.location = "/CMS/";
});
});
});
So the submit function on the forms doesn't work..
What's intresting is that I also have another ajax on the page when some li element get clicked and on the done function there I also have the form submit function and it works there.
Is there something wrong with this code?

Try this.
$(document).ready(function() {
$.ajax({
url: "pages/"+page+".php",
cache: false
}).done(function( html ) {
$('#main').html(html).css({"max-height":mH-30,"height":mH-30}).jScrollPane();
$('form').not('#loginf').submit(function(event) {
event.preventDefault();
var inputs = $(this).serialize();
$.ajax({
url: "pages/"+page+".php?"+inputs+'&action='+param,
cache: false
}).done(function( html1 ) {
update(html1);
rs();
}).fail(function (){
window.location = "/CMS/";
});
}); });

Never mind, i solved it by looking into this question answers:
problems with ajax request in page with form. jquery
The problam was as they said there with the function(event) so I changed it to function(e) wierd why the first one didn't work.

Related

on click edit button i am not getting value of shift start time and shift end time while editing

$(document).on("click", ".edit_record", function() {
var edit_id = $(this).data('shift_id');
$('#theTable tr:not(:first)').remove();
$.ajax({
type: 'POST',
url: 'ajax_task.php',
data: {
edit_id: edit_id,
shift_edit: 'shift_edit'
},
success:function(data) {
var response = JSON.parse(data);
$('#shift_name').val(response.shift_name);
$('#shift_start_time').val(response.shift_start_time);
$('#shift_end_time').val(response.shift_end_time);
$('#shift_data_iud').val(response.shift_id);
}
});
$("#insert-more").hide();
$('#myModal').modal('toggle');
});
Any one who can help me and thanks in advance

Sharepoint How to change function of new document

I have a document library and whenever I click on the new document (https://imgur.com/a/X4ATVX2) it will show this(https://imgur.com/a/6ExJ0Lr) for me to upload a document. How do I change this, so that it will display this (https://imgur.com/a/2JZvPDc) instead? I want to create a new document set instead of uploading a document file. Please advise.
I've watch some guides on the internet, their new is at this position. (https://imgur.com/a/X4ATVX2)
Add the code below into script editor web part in list view page.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
var listTitle="Test600DL";
var rootFolder=_spPageContextInfo.webServerRelativeUrl+"/"+listTitle;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/contenttypes?$select=StringId&$filter=Name eq 'Document Set'",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
if(data.d.results.length>0){
var contentTypeId=data.d.results[0].StringId;
var urlString="ContentTypeId="+contentTypeId+"&RootFolder="+rootFolder;
var $newDocumentLink=$("a[id^='idHomePageNewDocument']");
$newDocumentLink.attr("onclick",$newDocumentLink.attr("onclick").replace("Upload.aspx","NewDocSet.aspx").replace("RootFolder=",urlString));
$newDocumentLink.attr("href",$newDocumentLink.attr("href").replace("Upload.aspx","NewDocSet.aspx").replace("RootFolder=",urlString));
}
},
error: function (data) {
//alert("Error");
}
});
});
</script>

How to store variable data in success ajax to global variable (and call it in another function)

Here is my code.
<head>
<script>
var myGlobal ={};
</script>
</head>
<body>
$(function ()
{
$.ajax({
url: 'test.php',
data: "",
dataType: 'json',
success: function(data)
{
var vname = data.name;
my_global.push(data.name);
}
alert('The user selected: ' + my_global.newval); // i will use this value(vname value)
I would like to use VNAME value in other function..
Put all the code in the same script tags. What you wrote won't even work. The ajax code will just be displayed as text and not handled as script.

Can't get the text inside label tags inside jquery-ajax function

I have the following JQuery/AJAX code:
$("button#submit").click(function () {
var form = $('#pick-status-form');
var selectedStatusID = form.find('input[name=statusesList]:checked').val();
//Get the last checked value of the Radio Button
$.ajax({
type: "GET",
url: "updateStatusID.php",
data: { 'refID': lastRefId,
'statusID': selectedStatusID
},
success: function (msg) {
var selectedText = $.trim($('input:radio:checked').parent('label').text());
alert(selectedText);
//Get the text next to the radio button
$("button.btn.btn-default,button.btn.btn-primary").removeClass("disabled");
},
error: function () {
alert("Error");
}
});
});
$("input:radio").removeAttr("checked");
});
The following code:
var selectedText = $.trim($('input:radio:checked').parent('label').text());
alert(selectedText);
Works great in the following function :
$('.statuses-list').change(function () {
var selectedText = $.trim($('input:radio:checked').parent('label').text());
alert(selectedText);
});
But when I put it in the AJAX function it doesn't work (get a null alert).
My question is how can I fix it?
data: {
'refID': lastRefId,
'statusID': selectedStatusID
},
What is lastRefId ? Open your console in browser , I think you will get the js error

JQuery UI catcomplete not returning selected result

I am using JQuery UI remote autocomplete with Categories.
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
cat = currentCategory;
self._renderItem( ul, item );
});
}
});
$(function() {
$( "#birds" ).catcomplete({
delay:0,
source: "/search.html?term="+ $("#birds").val(),
minLength: 2,
select: function( event, ui ){
alert(ui.item.value);
}
});
});
The following is the result I get from the source:
[{"value":"Just a Product","id":"1","category":"Category Name"}]
The problem is that I can't get the alert(ui.item.value) to work and display the selected item.
Any help please?
Thanks.
This is not how you deal with the source.
see this.. http://api.jqueryui.com/autocomplete/#option-source
you can use
array
string
callback function
if you want to receive data from a page in json format, use jquery's $.ajax()
see this for ajax http://api.jquery.com/jQuery.ajax/
you can do something like
$.ajax({url: 'search.php?term='+$("#birds").val(),
dataType: 'json',
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Accept","application/json");
},
async: false,
success: function(data){
bArray=new Array;
bJson=data;
bArray.push(bJson[0].value);
bArray.push(bJson[0].id);
bArray.push(bJson[0].category);// for multiple records put these 3 lines in loop and replace 0 with a counter
}
});
$( "#birds" ).autocomplete({
source: bArray,
select:function(event,ui)
{alert(ui.item.value);}
});
dont forget to declare bArray, bJson
BUT i would still say you are doing it wrong. Instead of using value,id,category together you use use only one of them as autocomplete. can you tell what are you exactly showing in autocomplete