2011-11-04 10 views
0

보통 저는 .NET에서 작동하지만 매개 변수가있는 다른 PHP 스크립트를 통해 아약스 게시를 호출 한 다음 저장 프로 시저를 호출하는 PHP 페이지가 있습니다. 그러나 mysql 데이터베이스에 쓸 때 작동하지 않습니다. 아무도 내가 잘못하고있는 것을 말해 줄 수 있습니까? 어떤 도움을 주셔서 감사합니다.PHP, jquery ajax 호출이 작동하지 않습니다.

JQuery와 통화

$(document).ready(function() { 
      $('#ValidateTest').hide(); 
      $('#cf_submit').click(function() { 
       if ($('#cf_message').val() == '' || $('# cf_name').val() == '') { 
        $('#ValidateTest').html('Please complete.').css({ 'color': 'red' }).show(); 
        return; 

       } 

       var parameters = { 
        'name': $('#cf_name').val(), 
        'message': $('#cf_message').val() 
       }; //Use JSON to pass parameters into ajax calls 


       //Make ajax call to post to database 
       $.ajax({ 
        type: 'POST', 
        url: 'SendTest.php', 
        datatype: 'json', 
        data: parameters, 
        success: function() { 

         $('#ValidateTest').html('Thank-you!').css({ 'color': 'green' }).show(); 

        } 
       }); 
      }); //End button click 

     }); //end jquery call 

PHP 스크립트

<?php 
$con = mysql_connect('host', 'username', 'passw'); 
if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("", $con); 
mysql_query("CALL sp_CreateTestimony("$_POST['message']", "$_POST['name']")"); 
mysql_close($con); 
?> 
+0

작동하지 않는 기능은 무엇입니까? –

+0

IT가 데이터베이스에 게시하지 않습니다. 뭐가 잘못 됐는지 나는 잘 모르겠다. 또한 나는 방화범이 끌려 오는 콘솔을 점검했다. 심지어 성공 함수가 실행 되더라도, 아약스 호출이 호출되는 것처럼 보이지 않는다. – user516883

+0

[mysql_error] (http://php.net/manual/en/function.mysql-error.php)에서 mysql을 가져오고 있습니까? 또한,'host'가 오타이기 전에 누락 된 따옴표를 사용하고 있다고 가정합니다.하지만 수정해야합니다. –

답변

1

당신은 JSON을 사용하여 Ajax 요청하고 있습니다. 그래서 json을 해독해야만합니다.

$data = json_decode($_POST['data']); 

그런 다음 $ data 배열을 사용하여 메시지와 이름에 액세스 할 수 있습니다.

관련 문제