2016-05-26 5 views
0

メールチンパンジーAPI 3.0を使用してメールチンパンジーフォームを作成しようとしています。AJAXトラブル、PHPから返信を返す

これまでのところ、jQuery Validationプラグインで検証し、jQuery Formプラグインを使用してPHPスクリプトに投稿するフォームがあります。 PHPフォームは、複数のテストに基づいて動作しています。私はまた、データがフォームからPHPスクリプトに渡っていることを確信しています。つまり、PHPスクリプトからページにデータを戻すことは、物事が崩壊するところです。

ここでは、JSの側面があります。

// jquery form for submitting —— this is where the part that is not working, I just want back an error code (e.g., 400, 404, 500) or status (e.g., pending, subscribed) and pass that to the var user_status. 
    submitHandler: function(form) { 
    jQuery(form).ajaxSubmit({ 
    url: '/mc_ajax/process_mc_getstatus.php', 
    success: function() { 


     // translate variables form php to js // 
     function reqListener() { 
     console.log(this.responseText); 
     } 
     var oReq = new XMLHttpRequest(); //New request object 
     oReq.onload = function() { 
     // var user_status = JSON.parse(this.responseText); 
     }; 
     oReq.open("get", "/mc_ajax/process_mc_getstatus.php", true); 
     oReq.send(); 

     alert(this.responseText); 

ここで、user_statusはPHPスクリプトから入力する変数です。

私は を使用していました。var user_status = JSON.parse(this.responseText); しかし、データがすでに解析されているため、エラーが発生しました。ここで

は、私は戻ってデータを送信するためのPHPファイルに持っているものである:「未定義」

// $json_data contains the output string 
    $json_data = curl_exec($ch); 

    // close cURL resource, and free up system resources 
    curl_close($ch); 

    // Get status from JSON // 
    $json_data = json_decode(utf8_encode($json_data)); 
    $user_status = $json_data->status; 

    echo json_encode($user_status); 

これは、現在、言う警告が得られています

+0

各ステップのvar_dumpを確認してください。$ user_statusはオブジェクトまたは配列ではない可能性があります。 – LordNeo

+0

$ user_statusはPHPスクリプトで確実に使用されています。 PHPスクリプトの終わりには、PHPスクリプトが動作していることを証明する電子メールを送るmail()があります。 $ user_statusを使用して、 – justsomeone

答えて

0

取得しました。 JSを次のように変更しました。

   // jquery form for submitting 
       submitHandler: function(form) { 
        jQuery('#mc-embedded-subscribe-form').hide(); 
        jQuery('#newsletter-form').append("<p class='inprogress'>Working on that for you.</p>"); 

        jQuery(form).ajaxSubmit({ 
         url: '/mc_ajax2/process_mc.php', 

         success: function(responseText, statusText, xhr, $user_status) { 
          jQuery('.inprogress').hide(); 
          // jQuery('#newsletter-form').append(responseText); 
          jQuery('#newsletter-form').append("<p class='thanks'>" + responseText + "</p>"); 
         } 
        }); 
関連する問題