1

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); 
    }});
});
3
  • Could you post the JSON you are receiving? Commented Feb 4, 2013 at 3:27
  • how does the code at the server looks like, code that is responsible for sending data to the client Commented Feb 4, 2013 at 3:27
  • 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' Commented Feb 4, 2013 at 3:28

2 Answers 2

2

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);
}
Sign up to request clarification or add additional context in comments.

5 Comments

so how do I access my json that i have parsed in. it woorked when i added json_encode('hello')
Yeah I got that working anything else you could show or teach me. Im just learning all this stuff I've switched from asp.net to learn PHP for a course
how do i access the parsed data of my json in my php file eg. {'email':'[email protected]'}
for starters you can accept this answer :) and keep on reading blogs and stuff, with time we learn and with age we understand...
-1

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}
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.