2013-02-04 9 views
1

내 아약스 요청에 오류가 발생했습니다. 내 아약스 요청의 페이지에 이메일 주소 인 1 개의 값을 게시하고 싶습니다. 무엇이 잘못되었는지를 누군가가 나에게 수아약스 요청의 json 데이터 구문 분석 오류

오류 :

message=:[object Object], text status=:parsererror, error thrown:=SyntaxError: JSON.parse: unexpected end of data 

단지 $ .parseJSON가 오류없이하지만 경고 doiesn't 성공 기능 작동으로 변경 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); 
    }}); 
}); 
+0

당신이 받고있는 JSON을 게시 할 수 있을까요? –

+0

서버의 코드는 어떻게 보이며 클라이언트에게 데이터를 전송하는 코드입니까? – dakait

+0

아직까지는 그 방법을 모르는 상태입니다. json 파서가 필요합니다. 난 정말 'true'또는 'false'빈 문자열을 반환하는 것입니다 – ONYX

답변

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'

예 게시 한 코드에서 json이 수신 될 것으로 예상 함 getemailaddress.php

당신의 PHP 파일에서

<?php 

    echo json_encode("hello"); 

?> 

을 넣어 시도하고 대부분의 아마 일이 밖으로 작동합니다 당신

편집

당신이

$responseVar = array(
        'message'=>'some message', 
        'value'=>'some value' 
        ); 
같은 배열을 전송하는 PHP 스크립트에서 예를 들어

ajax 요청의 성공 처리기에서 다음과 같이 할 수 있습니다.

success:function(data){ 
console.log(data.message); 
console.log(data.value); 
} 
+0

그래서 내가 json_encode ('여보세요') 추가 할 때 woorked 내 json에 액세스 할 어떻게 – ONYX

+0

대답을 참조하십시오 편집 – dakait

+0

그래, 네가 보여 주거나 가르쳐 줄 수있는 다른 일이있어. 난 그냥이 코스를 위해 PHP를 배울 수 asp.net에서 전환 한 모든이 물건을 배우는 – ONYX

-1

액세스 할 수있는이처럼 JSON :

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