is there something wrong with the server configuration? - php

hello there ive created a site that have the pagination using ajax request to change its content using ajax that request sql data and print it to html codes.
the first site : pilem21.com
this one work just fine,
but the second site wont work as i hoped.
the second site : nontonoke.com
is the anything wrong with the server? or is it on my code?
here is the example of my codes requesting the pagination data
var a = $(".film2numb").val();
return $.ajax({
type : "GET",
url : "php/controller1.php?page=semuafilm",
data : "data="+a,
success: function(data){
$('.semuafilm').load('php/film.php',function(){$("img.lazy").lazyload();});
},
});

Related

AJAX Call 404'ing on staging server

I have AJAX form submission working fine locally. But when pushed to my staging server the process page is 404'ing. I cannot access it directly neither as it 404's but checking on the server and its 100% there with correct permissions too.
The code for the AJAX:
$('body').on('submit', '.product-form', function(e){
e.preventDefault();
$.ajax({
url : '/wp-content/themes/hinge_client_theme/page-templates/template-parts/template-logic/send-form.php',
type : 'POST',
data : thisForm.serialize(),
before : $(".error-message").remove(),
success : function(data) {
// removed for question
},
});
});
That send-form.php is 404ing on the network tab, any ideas whats going on? Working fine locally.
This a WordPress site but not sure if that is whats affecting it since it works locally.
The URL its trying to call on staging is:
http://staging.domain.com/wp-content/themes/my-theme/page-templates/template-parts/template-logic/send-form.php
You have to use url like this for staging
url : '/staging/wp-content/themes/hinge_client_theme/page-templates/template-parts/template-logic/send-form.php',
Because you are in folder "staging".

Show each response of php file using ajax

I use ajax type for send data to php file and get response and show. In my php file i have
while($i<14){ echo $i.'<br />'; $i++;}
that return 14 replay.
So, my webpage when call data with ajax method, after some secounds, show all 14 results. But i want get live response from my ajax file.
So i want my webpage show :
1
...
and then
1
2
....
etc
This is my Ajax code that return all response together in shower div.
I want get live responses. for any responses that sent from php file
function update_table(uptype){
$("#shower").html("Loading...");
var dataString = 'type=' + uptype;
$.ajax({
type: "POST",
url: "motor.php",
data: dataString,
cache: false,
success: function(html) {
$("#shower").html(html);
}
});
return false;
}
What you are asking is not possible with your current setup.
Think of an ajax-call to a PHP-script is like visiting a website like www.example.com/yourscript.php
PHP will then server-side render a code which is sent to your web-browser. This is a one call and one answer operation. PHP will not dynamically add elements to the website. Neither will it then be able to dynamically send answers to your ajax-call. What you have to do to solve this is storing the progress of the PHP script somewhere, and do several calls to get a update on the status.

SEO friendly url creation using js, php in html page

I am developing a website for a client using html, js and php. For any database call i am using ajax call
$.ajax({
type: 'POST',
url: "index2.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg, status) {
dosomething(msg);
},
error: function (msg, status) {
console.log("failure");
console.log(msg);
}
});
and php pages returns me the output. The problem is that index.html page url is not getting changed.....I want it to change say index.html?id=23 (creating query string in html page)
Basically my aim to make it SEO friendly url like index.html/helloppl
What is the best method to do this. While googling i found link for doing....still i need to create query string here...any help is appreciated.
Creating SEO fridenly url.
Creating query string in html
The problem is that index.html page url is not getting changed. I want it to change say index.html?id=23 (creating query string in html page)
Ans: if you want to change the url like you have mention above this the ajax will not the way to do this . This can be done in simple way go to the url i have provided and look at the topic.
http://html.net/tutorials/php/lesson10.php
Basically my aim to make it SEO friendly url like index.html/helloppl. What is the best method to do this. While googling i found link for doing this. I still need to create query string here.
Ans: This can be done with htaccess. Go To The Link
Jquery ajax() messing with my .htaccess mod_rewrite

jquery ajax call of mysql

I have found many threads regarding this issue, but unfortunately I couldn't get it running. Problem is I don't know much about JQuery.
I am trying to make an Ajax call using JQuery in order to fetch multiple records from a mysql database. I have the following function :
function updateWebpage ()
{
$.ajax({
url: './sale/api.php', //the script to call to get data
data: "", //you can insert url argumnets here to pass to api.php
//for example "id=5&parent=6"
dataType: 'json', //data format
success: function(rows) //on recieve of reply
{
for (var i in rows)
{
var row = rows[i];
var username = row[0];
var stateId = row[1];
$('#output').append("<b>id: </b>"+username+"<b> stateId: </b>"+stateId)
.append("<hr />");
}
}
});
};
My api.php is executing a mysql query with something like this:
$array = retrieveUsersInfo('%'); //fetch result
echo json_encode($array);
My main issue, is how to debug an issue like this? Since ajax is calling asynchronously another file, I cannot view any errors. From my firefox debugger, I can see that the $.ajax function is entered, but success is not.
Thanks in advance.
a couple things to try.
hit the api url directly in a browser (not through ajax) and make sure it returns the valid response.
add an error: function(err){} to your jquery ajax call. this method will get called if there is something other than a 200 response back from the server.
I use Chrome's developer tools more than firefox/firebug. It has a Network tab in it that shows me all the communication between the client and the server. You should see a call out to your api in that tab.
just off hand, i think you need to make sure the mime-type is set to text/json in your php file.

PHP SCript Not Accepting AJAX Data

This is really bizarre. I am trying to submit data to the server and have a PHP script parse the data and then send back a response. A correctly formed URL is being sent:
http://localhost/ajax/test.html?row=rec_no_1
, but the server does not seem to respond with content from the PHP script despite a return code of 200. In fact, Developer Tools (in Google Chrome) doesn't say anything about the PHP file. The AJAX "data" statement must be formatted properly otherwise I wouldn't get the correct URL. POST (instead of GET) doesn't help.
If I change the AJAX data to a string, then it works fine. This implies there is something wrong with the AJAX data. But I can't understand what given that the URL is correctly formed and does change depending on which row I select.
Any ideas?
Here is the Javascript:
$(document).ready(function() {
$(".submit").click(function() {
$.ajax({
type: 'GET',
url: 'getTable.php',
dataType: 'html',
data: {row: $('input[type='checkbox']:checked').val()},
//data: {row: 'rec_no_2'},
success: function($result) {
$('.tableHolder').text($result);
}
});
return false;
});
});
Here is the PHP code:
<?php
if (isset($_GET['row'])) {
$tableRow = $_GET['row'];
echo $tableRow;
}
else
echo 'TEST';
?>
Your syntax is incorrect:
$('input[type='checkbox']:checked').val()
You should use double quotes around checkbox:
$('input[type="checkbox"]:checked').val()
Anyway do a console.log( $('input[type="checkbox"]:checked').val() ) before the ajax call just to find out which value is being sent.
Try moving your javascript file to server. Ajax don't work on cross domain. You are running the javascript file on localhost and trying to fetch information from live server. Keep both php and javascript file on same server, either live or localhost. It will work fine.
One more thing, try changing the url parameter of your ajax request. try complete url or try putting or not putting a slash / before your filename.

Categories