Reputation: 5859
Im getting an error 200 in my ajax request. Im wanting to post 1 value which is a email address to the page in my ajax request. Could someone tell me what is wrong
Error:
message=:[object Object], text status=:parsererror, error thrown:=SyntaxError: JSON.parse: unexpected end of data
just changed to $.parseJSON it works with no error but the success function doiesn't alert JQuery
$('#checkemail').click(function() {
var json = $.parseJSON({ "email": $('#email').val() });
$.ajax({
url:'http://' + location.host + '/buyme/include/getemailaddress.php',
type:'POST',
contentType: "application/json; charset=utf-8",
data: json,
dataType:"json",
success: function(msg) {
alert(msg);
},
error: function(msg, textStatus, errorThrown) {
alert( 'message=:' + msg + ', text status=:' + textStatus + ', error thrown:=' + errorThrown);
}});
});
Upvotes: 1
Views: 4106
Reputation: 1383
you can access your json like this:
$.ajax({
type: 'POST',
url : URL,
data: {wis_videoId:wis_v_id},
success: function(data){
if(data !=''){
var obj = JSON.parse(data);
alert(obj.message)
alert(obj.value)
}
},
error:function(request, status, error){
alert('', request.responseText);return false}
});
Upvotes: -1
Reputation: 2620
I haven't got that far yet I don't know how to do that at the moment. I need a json parser do. I i really need is to return a empty string that is either 'true' or 'false'
yes the piece of code you have posted expects json to be recieved from getemailaddress.php
in your php file try putting
<?php
echo json_encode("hello");
?>
and most probably things will work out for you
EDIT
for example from the php script you are sending an array like
$responseVar = array(
'message'=>'some message',
'value'=>'some value'
);
in the success handler of your ajax request you can do something like
success:function(data){
console.log(data.message);
console.log(data.value);
}
Upvotes: 2