I got a website built for my small business from a freelancer. The website is hosted at http://devopsnexus.com/. Everything looks fine except the form in the bottom which is sending GET instead of POST. Strangely, if I just copy the code within the form tag in a new html file, it works just fine.
Now the freelancer has vanished and I am trying to debug since hours without an luck. Can anyone point out what is wrong with html here?
The form is being submitted via AJAX in main.js using jQuery's $.ajax(). The form method isn't specified here, and is defaulting to GET. Here's the fix:
// Contact form
var form = $('#main-contact-form');
form.submit(function(event) {
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
var formData = $(this).serialize();
$.ajax({
url: $(this).attr('action'),
method: 'POST',
data: formData,
beforeSend: function() {
form.prepend(form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn());
}
}).done(function(data) {
form_status.html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(3000).fadeOut();
});
});
Related
Using the docs from here: https://developer.vimeo.com/api/upload/videos
This is my request body, POSTed to api.vimeo.com/me/videos:
upload: { approach: "post", redirect_url: "https://www.example.com/app/video", size: 5253880 }
I am getting back a valid upload response, and able to submit the upload.form just fine to upload my video, however am redirected to the default Vimeo success screen instead of my own /app/video screen as desired. There's a redirect_uri property on the response which is null, so for some reason they seem to be ignoring my redirect_url. What am I missing here?
Here is the complete code being used to create the request:
const size = e.target.files[0].size;
const XHR = new XMLHttpRequest();
const uploadParams = {
upload: {
approach: 'post',
redirect_url: 'https://www.example.com/app/video',
size,
},
};
XHR.addEventListener('load', $scope.upload, false);
XHR.addEventListener('error', $scope.uploadError, false);
XHR.open('POST', 'https://api.vimeo.com/me/videos');
XHR.setRequestHeader('Authorization', `Bearer ${vimeoToken}`);
XHR.send(JSON.stringify(uploadParams));
Just figured it out, leaving this up for anyone else who misses this part of the docs: you need to set the Accept header to "application/vnd.vimeo.*+json;version=3.4" which I wasn't doing, and it was still letting me upload, but just not processing my request params.
Could anybody please help me with this as i have tried several different methods all to no avail.
im trying to send the old image src name along with the new image data via ajax, but i can only manage to send 1 or the other and not both..
file = input.files[0];
newimagesrc=input.files[0].name;
oldimagesrc=oldsrc;
formData= new FormData();
formData.append("image", file , newimagesrc);
recent attempt failed formData2= new FormData();
recent attempt failed formdata2.append('oldimage', oldimagesrc);
$.ajax({
url: "UploadProfileImage.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(messagereturn1){
alert(messagereturn1);
}
});
No buttons or forms im afraid, strictly passing variable's onchange / onclick.
Not sure how to send the old image src through ajax as well as the new image data , i would like to send more variables if possible that have been passed into JS function..
var form_data = new FormData(); // Creating object of FormData class
form_data.append("image", file , newimagesrc) // Appending image parameter
form_data.append("oldimagesrc", oldimagesrc) //added a second variable then received in PHP as a $_POST['oldimagesrc']
PHP
if (isset($_POST['oldimagesrc'])){ $oldimagesrc=$_POST['oldimagesrc']; }
The following contact form http://wearedappr.com/contact.html send all informations to a google spreadsheet after submitting. However, it also redirects the user to https://script.googleusercontent.com (See image below)
I am trying to have a confirmation message appearing instead of the redirection. Something like "Thanks for contacting us! We will get back to you soon!" which would appear on the contact form page once we submit it instead.
Can someone help by any chance?
Here is form-submission-handler.js:
http://wearedappr.com/form-submission-handler.js
Try these.
1, Change your opening form tag to this:
<form class="gform pure-form pure-form-stacked" id="google_form_submit">
2, Add the following to your code before the closing body tag
<script type="text/javascript">
$('#google_form_submit').submit(function(e){
e.preventDefault();
var formData = $('#google_form_submit').serialize();
$.ajax({
type : 'POST',
url : 'https://script.google.com/macros/s/AKfycbzBvgWZZUgFbxCAlhPG4429wth61Rm7kymPaui3d5328UHHOiA/exec',
data : formData,
dataType : 'json',
encode : true
}).done(function(data) {
if(data.result == 'success') {
// Form submission was successful and accepted by google.
// You can show your success message here
} else {
// Form was submission failed for some reasons.
// You can examine the response from google to see whats missing
}
}).fail(function (jqXHR,status,err) {
// Form submission failed due to some network or other errors
// I am alerting the error but you can do anything else with it
alert(err);
});
});
</script>
Pardon my untidy codes... am posting the answer from a tablet.
If you see any thing wrong let me know so I can fix
I am trying to send an extra data with ajax. I used (form).serializeArray() and added an extra data. when I am trying to send it via ajax, the alert showed me that the extra data wasn't added to the the serialized array.
This is my code:
$('#addrows').on('click',function(e){
var imgsrc= document.getElementById("imgz").src;
alert(imgsrc);
e.preventDefault();
var data_save = $('form').serializeArray();
data_save.push({ name: "imgname", value: imgsrc});
$.ajax({
url:"add.php",
cache:false,
method:"POST",
data:data_save,
success: function(data_save){
var obj = JSON.parse(data_save);
console.log(obj);
t.row.add( obj ).draw( false );
alert(obj);
}
});
});
});
I have tested the above example and everything seems fine over there. Also I dont see alert after:
var data_save = $('form').serializeArray();
data_save.push({ name: "imgname", value: imgsrc});
So try adding:
console.log(data_save);
and check the response or send me the screenshot of data that get passed in developer console.
I dont know what was wrong but then suddenly it worked.
I have searched many times and find examples which match my code structure perfect. Yet I am not getting the results from my ajax to display on the input box.
I get results from the POST that have been evaulated with firebug and everything looks great.
Here is the javascript im using.
<script type="text/javascript" language="javascript">
$(function () {
$("input.FamousPerson-List").autocomplete({
source: function (request, response) {
$.ajax({
url: "/FamousPeople/FPPAutoComplete",
type: "POST",
dataType: "json",
data: {
searchText: request.term,
maxResults: 12
},
success: function (data) {
response($.map(data, function (item) {
return {
value: item.DisplayName
}
}))
}
});
}
});
});
Here is a link of the actual code I am using on the web.AutoCompleteTesting Type just about any letter in one of the boxes below to invoke it.
Thanks.
If you look closely at the request being sent up, you'll notice that a callback parameter is being added. Weird, right? Since you're doing a local AJAX post, not a cross-domain (JSONP) one.
I noticed that your project includes jQuery Validate. According to this answer to a question dealing with a similar problem (performing a JSONP request instead of a normal JSON request even though you asked for one), it's a known issue in jQuery validate.
Judging by the other answer, you can change your version of jQuery or perhaps use a patched version of jQuery validate (found here).