I have an .htacess which is now working perfectly, on this page:
http://www.lebmotors.com/new/pror I have an ajax pagination file prorajax.php
clicking it it gets to index.php
$pag1->setContainerPage("http://www.lebmotors.com/new/prorajax"); This turns to an ajax link, but clicking it reached homepage index.php instead
This is the link generated by pagination class
<a href='#' onclick='Submit_To_Ajax(\"$curentpage?xc=8&page=1$queriess\");'>
<< </a>
This is the ajax function:
function Submit_To_Ajax(page)
{
xmlHttp = AjaxHttpObject();
if (xmlHttp==null)
{
alert("Your browser does not support AJAX !!!");
return;
}
else
{
}
xmlHttp.open("GET", page, true);
xmlHttp.onreadystatechange=StateChanged;
xmlHttp.send(null);
}
function StateChanged() {
if (xmlHttp.readyState == 4)
{
document.getElementById('AjaxDiv').innerHTML=xmlHttp.responseText;
}
else
{
document.getElementById('AjaxDiv').innerHTML='<img src="img/loading.jpg">';
}
}
RESOLVED This was the reason in pagination.inc.php
href = "#" removing this resolves the issue
Related
Hello I have change password using Ajax (this is a short version of the code):
var password = document.querySelector('[name="password"]').value;
action = 'http://localhost:8012/market2/market2/public/account/query/';
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
}
xmlhttp.open("post",action + password, true);
xmlhttp.setRequestHeader("X-CSRF-TOKEN", document.getElementById('token-csrf').value);
xmlhttp.onreadystatechange=function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responseText == "false") {
document.getElementById("error_password").innerHTML = "You actually password is wrong!";
return false;
} else {
document.getElementById("error_password").innerHTML = "OK";
return true;
}
}
}
xmlhttp.send();
}
And my csrf-token:
<input type="hidden" name="_token" id="token-csrf" value="{{ csrf_token() }}">
I don't know did I correct add parameter X-CSRF-TOKEN to my script. First I have error ajax 419 (unknown status) so I added X-CSRF-TOKEN and now I have error 500 (Internal Server Error). I also tried this: Laravel 5.5 ajax call 419 (unknown status)
Edit Post:
Is't my query method:
public function queryPass($pass) {
$user = Auth::user();
$current_password = $user->password;
if(Hash::check($pass, $current_password)) {
$updatePassword = App\User::where('id', $user->id)->update(['password' => bcrypt($pass)]);
echo "true";
} else {
echo "false";
die;
}
}
And route:
Route::get('account/query/{pass?}', 'UsersController#queryPass');
First problem was that he missed use Illuminate\Support\Facades\Hash; at the top of his controller, he used use Hash;, second thing when we resolved that was that, he was returning a boolean from inside a controller, when he is supposed to return an object which implements __toString method or a string, so he returned a correct response in this case a string "true" and "false"
Am doing a simple ajax call as follow...
The following code is in index.html.
$("#tmTrendinSignIn").click(function(event){
event.preventDefault();
jQuery.post("http://code.xxx.com/workspace/xyz/xxx/login/authenticateuser",{
'sleUsername': $("#sleUsername").val(),
'slePassword' : $("#slePassword").val(),
},function(strData,strTextStatus,objXMLHttpRequest){
if (strData != 'Invalid username or password!!'){
window.location.replace("dashboard.html");
$("#dashboardmenu").append(strData);
}else
{
$('#loginTmTerror').append("<span class='label-group-addon'><i class='fa fa-times-circle-o text-danger'></i> </span><label class='control-label'>"+strData+"</label>");
return false;
}
});
});
Here am getting strData(Properly), now i need to append this strData to another file called 'dashboard.html'.
I'm trying to send a variable to the server, using XMLHttpRequest.
I tested it on local on a non-Wordpress file and it works.
But on production, on my Wordpress file, the onreadystatechange AJAX status doesn't get to 200.
Is there anything I need to be aware when XMLHttpRequesting in Wordpress?
<script>
params = "parameter=" + value;
request.open("POST", "../myfile.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function()
{
if (this.readyState == 4)
{
if (this.status == 200)
{
if (this.responseText != null)
{
console.log('Request completed');
}
else console.log("Ajax error: No data received")
}
else console.log("Ajax error: " + request.statusText );
}
};
request.send( params );
// 'request' is 'XMLHttpRequest()' or 'ActiveXObject("Microsoft.XMLHTTP")'
// depending on browser
</script>
To create the code I followed the 2nd example of my O'Reilly book.
Any suggestion'll be much appreciated!
Thanks
Ultimately there is nothing wrong with this script.
I think it was due to the work frame I was using (Roots theme for Wordpress).
I change it for Handcrafted and I solved the problem.
I need a very basic, simple and lightweight AJAX script.
Does anyone have a shell of such a script they can share?
Here's what I have:
I have a PHP script on the server that echo's the current date and time on the server
I just need the javascript that calls the php script and loads the echoed text string into a js var so I can use it in my app
(the reason I need the server's clock is that all visitors to the site have to work off the same clock. The app does not work for visitors outside the server's timezone.)
Thanks for helping out.
JQuery is perhaps the right answer for AJAX but you can also do this in plain old Javascript as follows:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(){
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//the callback function to be callled when AJAX request comes back
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","<<url of web address>>",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
You can find a simple example here:
AjaxCall = function(Data, WebServiceURL, Callback) {
var request;
var url = WebServiceURL;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.status === 200) {
Callback(request);
} else {
alert("Sorry, an error occurred. " + request.responseText);
}
}
};
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(Data);
} else if (window.ActiveXObject) {
url += "?" + Data;
request = new ActiveXObject("Microsoft.XMLHTTP");
if (request) {
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.status === 200) {
Callback(request);
} else {
alert("Sorry, an error occurred. " + request.responseText);
}
}
};
request.open("GET", url, true);
request.send();
}
}
};
The the ajax functionality in jQuery is great but does mean a greater page download for one simple Javascript function.
You can find a downloadable fully worked example on my blog here:
http://www.willporter.co.uk/blog/simple-ajax-script.aspx
It uses ASP.NET on the server side but you should get the idea.
jQuery has made very simple ajax methods for you to use. You can find more information about them here.
Sample:
$.ajax({
type: 'GET',
url: '/SomeUrl/On/The/Server',
data: { SomeValue: 10 },
success: function(data, status)
{
// On Success
},
error: function(data, status)
{
// On Error
}
});
Look into this maybe : http://www.scriptiny.com/2011/01/simple-ajax-function-example/
jQuery is a more reliable library overall, but the lightest-weight AJAX methods I have found are the extremely simple Feather AJAX, coming in at 1.6 KB (with room for compression), or a one-liner snippet that I can't guarantee.
The risk of extremely lightweight libraries is that if they break, you're relying on the owner to fix it instead of a team of developers.
An alternative approach to solving your problem is to based your times on UTC instead of server-local time. You can even show the client local times based on that utc time, with a little work.
May I suggest AJAX Generator?
I am developer, and it is commercial tool but it has demo as well.
What you could do with that tool is:
put annotation on your PHP function
run AJAX Generator on PHP source file
include generated JavaScript file in HTML page and use PHP service as if you were calling function
To make it more clear, here is example code:
//example.php
<?php
//#WebService
function getServerDate(){
return date('m/d/Y h:i:s a', time());
}
?>
Now run generator on: example.php
Output would be two files: example_service.php and example_caller.js
Now you need to:
add example_service.php in same directory where is example.php and
include example_caller.js in index.html
Sorry for posting image instead of HTML code, but it wasn't showing properly.
when I Implemented chatting Function , I use Ajax to send messages between file to another .
so ,
it is working well on local host .
but , when I upload it in to remote server it doesn't work.
can U tell me ,why ?
is an Ajax need Special configuration ?
Ajax code :
function Ajax_Send(GP,URL,PARAMETERS,RESPONSEFUNCTION){
var xmlhttp
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e){
try{
xmlhttp=new XMLHttpRequest()
}
catch(e){
alert("Your Browser Does Not Support AJAX")
}
}
}
err=""
if (GP==undefined) err="GP "
if (URL==undefined) err +="URL "
if (PARAMETERS==undefined) err+="PARAMETERS"
if (err!=""){alert("Missing Identifier(s)\n\n"+err);return false;}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState == 4){
if (RESPONSEFUNCTION=="") return false;
eval(RESPONSEFUNCTION(xmlhttp.responseText))
}
}
if (GP=="GET"){
URL+="?"+PARAMETERS
xmlhttp.open("GET",URL,true)
xmlhttp.send(null)
}
if (GP="POST"){
PARAMETERS=encodeURI(PARAMETERS)
xmlhttp.open("POST",URL,true)
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp.setRequestHeader("Content-length",PARAMETERS.length)
xmlhttp.setRequestHeader("Connection", "close")
xmlhttp.send(PARAMETERS)
}
}
Two points really,
Firstly, If the URL is on a different domain, default security model in your browser might stop that working.
Secondly, have a look at JQuery, this bulk of code would be reduced to 2 or 3 lines.
Have a look here: http://docs.jquery.com/Tutorials