weixin_33713503 2016-02-07 17:59 采纳率: 0%
浏览 60

PHP MVC的jQuery的ajax

Im beginner and have just simple PHP MVC for JQUERY SPA, and just wonnt to use Jquery Ajax to index.php, like front controller calling RouterControler and class AjaxKontroler with registruj() method...using user model to add new user to MySQL..

 class AjaxKontroler
{
    public function registrovat()
    {       

        if ($_POST)
        {
            try
            {

                $spravceUzivatelu = new SpravceUzivatelu();
                $spravceUzivatelu->registruj($_POST['email'],$_POST['heslo'],$_POST['hesloZnovu'],$_POST['jmeno'],$_POST['prijmeni'],$_POST['telefon'],$_POST['ulice'],$_POST['mesto'],$_POST['psc'],$_POST['captcha']);
                $spravceUzivatelu->prihlas($_POST['email'], $_POST['heslo']);               

            }
            catch (ChybaUzivatele $chyba)
            {
                $this->pridejZpravu($chyba->getMessage());
            }
        }
    echo "Registrace proběhla úspěšně"; 
    }

Singup form:

$("#dokoncitregistraci").click(function () {
    var email = $("#emailreg").val();

    var heslo = $("#hesloreg").val();
    var hesloznovu = $("#hesloznovureg").val();
    var jmeno = $("#jmenoreg").val();
    var prijmeni = $("#prijmenireg").val();
    var telefon = $("#telefonreg").val();
    var ulice = $("#ulicereg").val();
    var mesto = $("#mestoreg").val();
    var psc = $("#pscreg").val();
    var captcha = $("#captcha").val();

    console.log("jedu");
    $.ajax({
        type: "POST",
        url: "../ajax/registrovat",
        data: { 
        "email" : email,
        "heslo": heslo,
        "hesloznovu" : hesloznovu,
        "jmeno" :jmeno ,
        "prijmeni":prijmeni,
        "telefon":telefon,
        "ulice":ulice,
        "mesto" :mesto,
        "psc" : psc,
        "captcha" :captcha
        },
        dataType: "JSON",
        success: function(msg){
            alert("msg");

            }

But all signup inputs are correctly add ti MySQL like new row. I have no success response to work with. Are there some trick to use success response in MVC?

Browser just doesn't make any JS alert(). Sorry abeout using StackOwerflow, its my first question here ane no best practise for it:)

  • 写回答

1条回答 默认 最新

  • weixin_33733810 2016-02-07 18:14
    关注

    Your code looks fine overall. As far as I know, you don't need the double quotes in "email":email. It can be email:email, but that shouldn't be the problem.

    My instinct tells me to double check your ajax url:. Relative urls are tricky, as you have to make them relative to the page running the execution, not what the browser shows. I'd switch to absolute urls like http://www.example.com/ajax/registrovat/ until you are certain what the problem is. The last slash after registrovat is important for differentiating between a controller name and a value.

    You can also add an error: function() {} to get more information about what is going on.

    评论

    报告相同问题?

    悬赏问题

    • ¥15 PMM 9010/30P
    • ¥15 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段
    • ¥30 android百度地图SDK海量点显示标题