How do I debug jquery AJAX calls?
Make your JQuery call more robust by adding success and error callbacks like this:
$('#ChangePermission').click(function() {
$.ajax({
url: 'change_permission.php',
type: 'POST',
data: {
'user': document.GetElementById("user").value,
'perm': document.GetElementById("perm").value
},
success: function(result) { //we got the response
alert('Successfully called');
},
error: function(jqxhr, status, exception) {
alert('Exception:', exception);
}
})
})
How to debug ajax response?
After a much needed 10 hour break into the night, I solved the issue with a much clearer mind. I removed the dataType row and it worked for me.
As silly as it may sound, the table in the PHP page was not in JSON format, so when jQuery tries to parse it as such, it fails.
Hope it helps for you. If not, check out more suggestions here.
Before
$.ajax({
type: 'POST',
dataType : 'json',
url: 'queries/getsocial.php',
data:nvalues,
success: function(response)
{
console.log(response);//does not print in the console
}
});
After (Works now)
$.ajax({
type: 'POST',
url: 'queries/getsocial.php',
data:nvalues,
success: function(response)
{
console.log(response);//yes prints in the console
}
});
how to debug php during jquery ajax call
I figured out how to debug it. In the chrome debugger, select the Network tab, then select "screen_custom.php" from the list, then select the Response tab. It shows the output from the php. I uncommented the echo sql statement and could see that in fact, the form parameters are not being read, as I suspected.
Then I googled on that problem and found the solution was to modify the data paramenter js as shown below:
data: function(d) {
var form_data = $('#criteriaForm').serializeArray();
$.each(form_data, function(key,val) {
d[val.name] = val.value;
});
},
I don't know why the first method didn't work as I could see the correct parameters being sent in the header. But this works.
How to debug jQuery AJAX
After some research, this question was pretty much a duplicate of this one:
Debugging scripts added via jQuery getScript function
How to debug javascript returned from server after ajax call in Chrome debugger
use debugger
debugger; //this will stop and pause your project
var x = $("#something").val();
Related Topics
How to Loop Through All the Elements Returned from Getelementsbytagname
Password Encryption at Client Side
How to Develop Desktop Apps Using HTML/Css/Javascript
How to Use JSON Data to Populate the Options of a Select Box
Session Only Cookies with JavaScript
Convert Td Columns into Tr Rows
How to Position a Div in a Specific Coordinates
Inlining Ecmascript Modules in HTML
How to Localize a Simple HTML Website Page in My Case
Hide Select Option in Ie Using Jquery
Overriding a JavaScript Function While Referencing the Original
Uploading Image to Amazon S3 with HTML, JavaScript & Jquery with Ajax Request (No PHP)
How to Store a Byte Array in JavaScript
Completely Lost on How to Save Extension Popup Window Content
JavaScript Regex Returning True.. Then False.. Then True.. etc