ajax ile bir sınıf çağırıyor

1 Cevap php

I need some help with this please I can't get a handle on it.

Sorun bir ajax çağrısı ile statik yöntemleri ile bu durumda, bir sınıf yöntemi çağırmak istiyor.

I have put the helper class in the same folder as the script that is called by ajax for easy referencing and try to include it. Could it be that my refencing is wrong?

Ajax tarafından çağrılan dosyada bir TestClass yaparsanız ben bir yanıt alabilirsiniz.

class test {
    public function testit() {
    	return "testit";
    }
}
$t=new test;
$check= $t->testit();



switch($action) {
case "someaction":
    $data = array();
    $file='input_helper.php';
    include_once $file;

    $check= input_helper::ip_address();
    header('Content-type: application/json');

    $output = array(
    	"check" => $check,
    	"user" => $data
    	);

    echo json_encode($output);

    exit(0); // Stop script.

    break;
//...

EDIT FOR MORE CLARIFICATION

The action is set as a post variable in the ajax function The ajax url points to a script that takes some action based on the posted variables

teşekkürler, Richard

1 Cevap

<?php
  include_once 'your/class/path/helper_class.php';
  .
  .

PHP sayfanın en başında yapmalıdır. Gerçekten AJAX ile ilgisi yoktur. PHP dosyası geri arama vurulduktan aslında ise, o düzgün çalışması gerekir.

İsteğe bağlı olarak, bunu yaparsanız sizin yol, doğru olduğunu test etmek için:

 <?php 
     require 'your/class/path/helper_class.php';
     .
     .

Yol doğru değilse PHP bir ölümcül E_ERROR seviyesi hata atmak olacaktır.