没有经过$ .post的Jquery AJAX函数,无法找到任何语法错误

时间:2017-03-17 04:16:21

标签: javascript php jquery ajax wordpress

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/content_main"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:weightSum="1">

    <ImageView
        android:layout_weight="0.8"
        android:src="@drawable/logo"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        android:layout_weight="0.2"
        android:weightSum="1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:weightSum="1"
            android:layout_weight="0.25"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </LinearLayout>
        <LinearLayout
            android:weightSum="1"
            android:layout_weight="0.25"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </LinearLayout>
        <LinearLayout
            android:weightSum="1"
            android:layout_weight="0.25"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </LinearLayout>
        <LinearLayout
            android:weightSum="1"
            android:layout_weight="0.25"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
            <LinearLayout
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/free2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:gravity="center_horizontal"
                    android:text="this is text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

和&#34; one.php&#34;

<script type="text/javascript">
    function swapContent(cv) {
        $(".loading").html("loading-gif").show();
        $.post( "one.php", {contentVar: "cv"},function(data) { 
            $(".loading").html(data).show();
            alert('Info Sent!');
        });
    }
</script>

我将警报放在$ .post中,这样我就可以知道我的脚本失败了。我收到脚本中每个阶段的警报,直到$ .post停止显示警报。意思是代码出错的地方。但据我所知,似乎没有任何语法错误,这可能是什么原因导致无效?

1 个答案:

答案 0 :(得分:0)

搞定了!必须指定我试图发布到的文件的确切位置。由于文件属于wordpress主题,我必须使用<?php echo get_template_directory_uri();?>

指定其位置
$.post( "<?php echo get_template_directory_uri();?>/one.php", {contentVar: "cv"},function(data)