i found 404 error
var endpoint='';
var bookingform=$("#BookingForm").serialize();
jQuery.ajax({
url: endpoint,
type: "POST",
data:{'action':'submitform1','bookingform':bookingform},
processData: false,
contentType: false,
success: function (result) {
$("#propertydata").html(dat.data)
},
error: function(dat1){
alert("error");
}
You are sending ajax to empty URL -> var endpoint='';
You need to send it to wordpress ajax url like this:
<script type="text/javascript">
var endpoint = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>
You need to paste the above code in header.php file of your theme.
Secondly, in the success function, you are using the variable that is not defined (dat) you need to use something like this:
jQuery.ajax({
url: endpoint,
type: "POST",
data:{'action':'submitform1','bookingform':bookingform},
success: function (result) {
var dat = JSON.parse(result);
$("#propertydata").html(dat.data)
},
error: function(dat1){
alert("error");
}
});
Related
I am trying to send some variables(data),one is the checkbox text, and other is the value in the textarea field to the controller in Laravel through ajax, below is the script:
<script>
$('#btn1').on('click', function() {
$('input[type="checkbox"]').on('click', function() {
var aa=$(this).next('label').text();
var bb=$('textarea#txt2').val();
$.ajaxSetup({
headers:
{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
});
$.ajax({
type: "POST",
url: "/masterdata",
//dataType: 'json',
data: {aa,bb},
success:function(){
console.log(data);
}
,error:function(){
console.log("Error!!!!");
}
});
});
});
</script>
On trying to retrieve the request values in the controller, only the request token gets displayed, and the ajax function doesn't display the success or error message either.What am I missing here?
you need to set a variable on ajax success like this:
$.ajax({
type: "POST",
url: "/masterdata",
//dataType: 'json',
data: {aa,bb},
success:function(response){
console.log(response);
}
,error:function(){
console.log("Error!!!!");
}
});
Try your data as in this format:
data:{'posa': aa, 'posb': bb},
and
success:function(data){
console.log(data);
}
Hope this helps.
i found two issue in your ajax request.
you have to change data: {aa,bb}, to object like data: {aa : aa, bb : bb},
Your success response log is wrong. Current code success:function(), it should be success:function(data)
Full output of new code is :
<script>
$('#btn1').on('click', function() {
$('input[type="checkbox"]').on('click', function() {
var aa=$(this).next('label').text();
var bb=$('textarea#txt2').val();
$.ajaxSetup({
headers:
{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
});
$.ajax({
type: "POST",
url: "/masterdata",
dataType: 'json',
data: {aa : aa, bb : bb},
processData: false,
cache: false,
async :false,
success:function(data){
console.log(data);
}
,error:function(){
console.log("Error!!!!");
}
});
});
});
</script>
To get parameter value in controller use
/**
* Store.
*
* #param Request $request
* #return Response
*/
public function store(Request $request)
{
$aa = $request->input('aa');
$bb = $request->input('bb');
//Your code here
}
<script>
$('#btn1').on('click', function() {
$('input[type="checkbox"]').on('click', function() {
var aa=$(this).next('label').text();
var bb=$('textarea#txt2').val();
$.ajaxSetup({
headers:
{'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
});
$.ajax({
type: "POST",
url: "/masterdata",
//dataType: 'json',
data: 'aa=test'+'&bb=test',
success:function(){
console.log(data);
}
,error:function(){
console.log("Error!!!!");
}
});
});
});
</script>
When I use the code below, paging is not working. Where am I wrong?
var data = '';
$.ajax({ type: "GET",
url: "include/tables/data.php",
async: false,
success: function(data) {
$("#result").html(data);
$('#mytable').DataTable({});
}
});
I want to disable/prevent loading of the page until a JS call has been completed. I understand that the only way to do that is with $.ajax like so:
$.ajax({
url: "/acme/confirm_authentication.html",
async: false,
cache: false,
success: function(data) {
// loaded
}
Currently, I’m loading a partial page with .load() function like so:
var linkUrl = $('.js-dialog--on-load').attr('dialog-href') + ' #lga';
showDialogWindow(linkUrl);
function showDialogWindow(linkUrl) {
$('.container').append($("<div>").load(linkUrl, function(){
}).addClass('js-dialog'));
}
See demo: http://jsfiddle.net/SQDDD/1/
How can I translate this into an $.ajax call?
Remember, the reason I’m using .load() is so that I can load only part of the website (#lga).
asyc: false is (most of the time) evil ;-)
You may try something like :
function showDialogWindow(linkUrl) {
$.ajax({
url: linkUrl,
async: true,
cache: false,
success: function(data) {
$('.container').append($("<div>"+data+"</div>").addClass('js-dialog'));
}
});
}
Be aware that you lose the selector feature available in the load
Take a look at this example :
I have this html :
...
<body>
aaa
<p>bbb</p>
</body>
...
now getting the p element from ajax :
$.ajax(
{
url: 'http://jsbin.com/oFUMOtO/3/quiet',
type: "GET",
dataType: 'html',
success: function (data)
{
alert($("<div>").html(data).find( "p" ).text()); //alerts bbb
}
});
want to get response from url using ajax and jquery.
tried with this code
$(document).ready(function () {
$.ajax({
type: 'POST',
url: 'apexweb.co.in/apex_quote/uname_validation.asp?,
dataType:'jsonp',
success: function(data){
alert(data);
}
});
});
i want to display response as fail but i didn't get any response on browser
Help Me
Try this
$(document).ready(function () {
$.ajax({
type: "POST",
url: "apexweb.co.in/apex_quote/uname_validation.asp?",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function (data) {
alert(data.d);
},
failure: function (data) {
alert(data.d);
}
});
});
I have the AJAX-code, which calls to controller of CodeIgniter's back-end:
<script>
$(document).ready(function(){
$("#select_bank").change(function(){
selected_bank = $("#select_bank option:selected").text();
$.ajax({
url:'<?=base_url().'atm/select_region/&'+selected_bank; ?>',
success:function(msg){
}
});
});
});
So, I want to get this params in the controller (CodeIgniter), but, because of this is not at the any form, using the
$bank = $this->input->post('')
gives no effect. really, I'd like to clarify this moment
You need to tell the ajax function that you're sending POST data
$.ajax({
type: "POST",
dataType: 'html',
url: <?= base_url ?> + "atm/select_region",
data: {nameofpostvariable:valuethatyousend},
success: function(output){
},
error: function(output){
alert('error');
}
});
On the line data: {nameofpostvariable:valuethatyousend}, you are creating a $_POST['nameofpostvariable']