Ajax post error with no futher information - javascript

I need help with this stuff. Chrome doesn't have this problem, only Firefox. When I submit form, ajax creates tasks. My mysql queries ain't got any problems, I added tons of
if not working write mysql error into file
But all are successful. So here is the error
http://i.stack.imgur.com/KYq4L.jpg how to find out what the hell is this? My code of ajax is pure empty here it is:
$.ajax({
type: "POST",
url: '/modules/projects/ajax/ajax_import.php',
data: {
data: array,
id: projectNow,
}
});
Thats it.

First check ajax_import.php is available at this location or not.
/modules/projects/ajax/ajax_import.php
If file is exist at this location then just clear all content from there and just write test content as below.
<?php
echo "testing";
?>

Related

$.ajax POST not receiving data

If you wish to visit my webpage
Login details that can be used are
(case sensitive):
Username: stack
Password: stack
Click on yourhours tab.
My overall goal is to send all data from input boxes to a database. However currently I am just trying to get the interaction from the javascript and the PHP working. In the console I can see that the data variable has the value of "". I cannot see why this is happening.
PHP
<?php
$startTime = $_POST["startTime"];
echo $startTime;
?>
HTML
http://pastebin.com/7p9NiV44
Your javascript is working and is sending the value of the startDate input element to your sendHours.php. Your PHP-script is also correct.
By some reason your $_POST array isn't populated and it's not possible to come up with a solution based on your question alone. I would start by checking my php.ini, especially the setting post_max_size.
Also, you could try replacing your PHP-code with a simple <?php echo "Hello world"; ?> to verify that your setup is working to that extent at least.
not a solution but add the error section to get a better idea of what is going on.
function d(){
var startTime = document.getElementById("startTime").value;
console.log(startTime);
$.ajax({
type: "POST",
url: "sendHours.php",
data: {startTime: startTime},
success: function(data){
console.log(data);
},
error: function(err, status) { console.log(err);}
})
}

Ajax post isn't working

Quick question. I know this is a problem solved many times on stackoverflow, but if I try to make it work it no methodes work out for me. Am I doing it so bad? Here is my code:
$('.submit').click(function(){
$.ajax({
type: 'POST',
url: 'http://localhost/clicky%20game/index.php',
data:
{
userScore:score
},
succes: function(){
alert('succes');
}
});
});
This piece of code is inside a script.js (linked to click.php) and it sould send the data to index.php. But it doesn't, I check this with the code (inside index.php):
if (isset($_POST['userScore'])){
echo $_POST['userScore'];
}
It just keeps showing nothing, hope someone can help me with this, thanks in advance!
That's not how Ajax works. $_POST is a PHP method that stores global variables from page to page. If you pass a javascript variable to a page then PHP will never see it. If this was possible to do then everyone would be hacked in a matter of seconds. You should look into REST APIs. That's what Ajax requests are for. HTTP POST and PHP POST are two very different things, but they do the exact same thing.
What you want to do is store a POST variable with PHP with a Form using the POST method. Then you can send that to index.php.
<form action="index.php" method="POST">
<inputs></inputs>
</form>
Since you are using a regular button to click, you will have to prevent the default submission of the form:
$('.submit').click(function(e){ // added the `e` for the `event`
e.preventDefault(); // this will prevent the default action of the submission of the form.
$.ajax({
type: 'POST',
url: 'http://localhost/clicky%20game/index.php',
data:
{
userScore:score
},
succes: function(){
alert('succes');
}
});
});

Error in Passing Jquery variable to a php session variable with ajax

This question might seem a duplicate and There are many posts on how to pass jquery variables to php. Tried all of them none worked for me.
Here is what all I did.
From Jquery:
$.ajax({
url: '/test.php',
data: {"name":name,"phone":phone},
type: 'post',
success:function(data){
console.log("Succses");
}
});
In test.php
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['phone']=$_POST['phone'];
There is nothing complex in this code. It is so simple and am seeing the "Success" message on the console. When am trying to echo this sssion variable in another page, this is shown empty.
Any help is greatly appreciated.
Please use session_start() on the first line of your PHP code to make the session works for you for that page.
You might have following problems
Might be missing session_start()
You might getting blank values on $_POST
Do the debug for ajax call and don't forget to check print_r($_POST) has values in success or not.

Undefined index on ajax call only for one function

I have several different ajax calls on the same php page, but I get undefined index for only one function (createAlbum).
I send exactly the same parameters in each of my ajax calls. It worked fine for a few tests, but now it only works for the other ones, but not for this specific call.
I suspected that the .js file was still in the browser cache, so I cleared it and tried with other browsers, which worked for a few more attempts.
Now, I can't get it working on any browser, and definitely don't understand why.
Here is my ajax call :
$.ajax({
type: "POST",
url: BASE_URL,
data: {
action: "createAlbum",
data: JSONAlbum
},
cache: false,
success: callback
});
My php file handling the request ($_POST['action'] is always undefined with the above request) :
if (isset($_POST['action'])) {
switch ($_POST['action']) {
// Handle the action
// ...
}
} else {
echo 'ACTION : '.$_POST['action'];
}
The header containing the ajax parameters ("data" is a json containing one or more blob images, this might be the problem, but I didn't find anything saying so) :
And finally, the response containing the error :
I really hope this is not a dumb error of mine, but I asked a friend before posting, and he can't find the solution either.
Thanks for your help !
You said that the error not happens all the time (in some call yes, in other no).
The body post is sent, you see it in console. So we can exclude javascript problem.
So the problem is something that happens before or during the process.
PHP has some limitations on input vars, you can see it in php.ini.
I see that you send images in base64, so it's probable that something of these limitations are triggered.
See for example:
max_input_time
max_input_vars
post_max_size

Javascript variable to PHP variable?

Jquery function:
$(document).ready(function() {
$(".checkbox").click(function(){
var selVal = $(this).val();
$.ajax({
type: "POST",
url: 'remove_task.php', //This is the current doc
data: ({sel: selVal}),
success: function(data){
//alert(selVal);
console.log(data);
}
});
});
});
My PHP function in remove_task.php:
function remove_selected_task()
{
$task_to_remove = $_POST['sel'];
echo $task_to_remove;
}
if (isset($_POST['remsubmit']))
{
remove_selected_task();
}
Not able to pass this successfully. Can anyone help me out? Thanks in advance.
try to pass the $_POST variable into the function for ex:
remove_selected_task($_POST['sel']);
function remove_selected_task($task_to_remove)
{
echo $task_to_remove;
}
Start by trying to diagnose the issue using the browser dev tools. Press F12 to get the dev tools panel, and go to the Network tab.
Now click your checkbox and watch for what happens...
Does the network panel show the request being made to remove_task.php?
If not, then there's a problem in your javascript where it registers the click event. Maybe the selector is wrong or something like that.
If the network panel does show the request being made, click on it there to get more info about it, and then look at the request data and the response data.
Does the request send the data you're expecting it to, and in the correct format?
If not, then you'll need to debug your Javascript to see why. I can't really help with that unless I actually see the data, but you should be able to get an idea of what the problem is by what's being sent incorrectly. Maybe the checkbox value is wrong?
If it does look right, then move on to the response.
Does the response contain the data you expect?
If it has a 404 response code, then your URL is incorrect. Maybe the path is wrong?
If the response includes an error message, then you should be able to debug the PHP from that. It'll have the relevant line numbers in it, so that should be enough to get you going.
If the response is blank, then your PHP code isn't sending anything back: Maybe a syntax error (with error suppression), or maybe the program ends before it gets to echo the data. Either way, further debugging in the PHP will be required.
That's about as much help as I can give, given the info you supplied in the question. I hope that's enough to get you started.
This will solve your problem, and next time add the full code in your question.
you check if "remsubmit" exists in your php file, but you don't send it ! This should work by modifying the line data: ({sel: selVal}) as below :
$(document).ready(function() {
$(".checkbox").click(function(){
var selVal = $(this).val();
$.ajax({
type: "POST",
url: 'remove_task.php', //This is the current doc
data: {sel: selVal, remsubmit:"1"},
success: function(data){
//alert(selVal);
console.log(data);
}
});
});
});

Categories