The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
jQuery - JQuery, AJAX and JSON simple question
Discuss JQuery, AJAX and JSON simple question in the JavaScript Development forum on Dev Shed. JQuery, AJAX and JSON simple question JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 28th, 2012, 09:59 AM
|
|
Contributing User
|
|
Join Date: Aug 2012
Posts: 37
Time spent in forums: 6 h 44 m 41 sec
Reputation Power: 1
|
|
|
jQuery - JQuery, AJAX and JSON simple question
Hi, I am starting to learn jQuery, AJAX and JSON. I am trying to pass a variable to a PHP script called validate_user.php using the jQuery, AJAX, JSON technique. I keep getting the error SyntaxError: JSON.parse: unexpected character. I have tried a lot of ways to make it work.. and this is the code for the ajaxSubmit.js
Code:
$(document).ready(function(){
$('#loginbutton').click(function() {
$('#waiting').show(100);
$('#login-box').hide(0);
$('#message').hide(0);
$.ajax({
type: 'POST',
url: 'validate_user.php',
//data: {usuario : $('#usuario-field').val(), password : $('#usuario-password').val() },
data: {'usuario' : 'prueba', 'password' : 'pruebapass' },
dataType : 'json',
success : function(data){
$('#waiting').hide(500);
$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
$('#login-box').show(500);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
$('#waiting').hide(500);
$('#message').removeClass().addClass('error')
.text('There was an error.').show(500);
$('#login-box').show(500);
}
});
return false;
});
});
Can someone help me out, please? I tried to read on Google and resolve this yesterday, I am still reading today, but now I feel I need some assistance, don't know where exactly is the syntax error, hope it is something simple and some experienced user can help me with this. Regards.
|

November 28th, 2012, 10:18 AM
|
|
Contributing User
|
|
Join Date: Aug 2012
Posts: 37
Time spent in forums: 6 h 44 m 41 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by jaimitoc30 Hi, I am starting to learn jQuery, AJAX and JSON. I am trying to pass a variable to a PHP script called validate_user.php using the jQuery, AJAX, JSON technique. I keep getting the error SyntaxError: JSON.parse: unexpected character. I have tried a lot of ways to make it work.. and this is the code for the ajaxSubmit.js
Code:
$(document).ready(function(){
$('#loginbutton').click(function() {
$('#waiting').show(100);
$('#login-box').hide(0);
$('#message').hide(0);
$.ajax({
type: 'POST',
url: 'validate_user.php',
//data: {usuario : $('#usuario-field').val(), password : $('#usuario-password').val() },
data: {'usuario' : 'prueba', 'password' : 'pruebapass' },
dataType : 'json',
success : function(data){
$('#waiting').hide(500);
$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
$('#login-box').show(500);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
$('#waiting').hide(500);
$('#message').removeClass().addClass('error')
.text('There was an error.').show(500);
$('#login-box').show(500);
}
});
return false;
});
});
Can someone help me out, please? I tried to read on Google and resolve this yesterday, I am still reading today, but now I feel I need some assistance, don't know where exactly is the syntax error, hope it is something simple and some experienced user can help me with this. Regards. |
If someone is interested what was the issue, actually it was an issue with the validate_user.php file. I ran that on my browser and the script had something incorrect, so that was causing the issue
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|