Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX在Safari或Safari mobile中未启动_Javascript_Php_Jquery_Ajax_Safari - Fatal编程技术网

Javascript AJAX在Safari或Safari mobile中未启动

Javascript AJAX在Safari或Safari mobile中未启动,javascript,php,jquery,ajax,safari,Javascript,Php,Jquery,Ajax,Safari,出于某种原因,我的AJAX事件不会在Mac或iPad/iPhone上的Safari中启动。我是新手,所以这可能是程序员的错误,也可能是程序员的错误,但下面是我的代码: <form class='send-form'> <input type="hidden" name="csv-val" value=""> <input type="hidden" name="img-val" value=""> <button type='bu

出于某种原因,我的AJAX事件不会在Mac或iPad/iPhone上的Safari中启动。我是新手,所以这可能是程序员的错误,也可能是程序员的错误,但下面是我的代码:

<form class='send-form'>
    <input type="hidden" name="csv-val" value="">
    <input type="hidden" name="img-val" value="">
    <button type='button' class='send-it' onclick='$(sendTheData(event))'>
        Manual Submit
    </button>
</form>

<script>
    function sendTheData(event){
        var sendButton = $(event.target);
        var theForm = sendButton.parents('form');
        var theFormClass = sendButton.parents('form').attr('class');
        console.log("Parent form is " + theFormClass);
        $.ajax({
            async: "true",
            type: 'GET',
            url: 'save.php',
            data: $(theForm).serialize()
        }).done(function( msg ) {
            alert( "Data Saved: " + msg );
        });
        return false;
    }
</script>

请注意,带有类send form的元素由不同的jQuery脚本追加到文档中,并且在初始加载时不在页面上,因此可能会影响事情;我不确定。

尝试添加失败回调,可能会出现一些错误。。。 您可以通过以下步骤获得一个示例:

将onclick属性更正为onclick=sendthedata事件; 检查url是否正确。 将方法从GET更改为POST。
关于表单类的注意:您可以将id设置为特定的表单,然后将变量绑定到该id而不是类。尽量避免使用父函数和类似的函数,因为它们使用了太多的资源。您正在对所有元素进行循环,然后通过父函数,然后找到正确的函数,而不是直接针对正确的函数。

首先,onclick应该是onclick=sendTheDataevent;,修改后再试。谢谢你的提示。我确实修改了它,不幸的是它没有工作。我可以在中看出调用sendTheData函数是因为它向控制台发出注释,但该函数中的ajax事件没有触发。请检查url是否正确。您使用的是GET方法而不是POST。form变量已经是一个jQuery对象,您不需要再次包装它,例如,theForm.serialize,我也不明白为什么您要这样设置form变量,通过查找parent,parent已经有class.send form,所以您可以简单地将该变量更改为var theForm=$”.send form';我使用find parent的原因是,这些表单中有不止一个具有send form类。它们由不同的jQuery函数追加。然而,我确实将方法从GET改为POST,并在我的PHP文件中将其从GET改为POST,它的工作非常有魅力。谢谢!我不知道你是否可以将其作为回复而不是评论提交,这样我就可以将其标记为正确,但如果你可以,它可能会对其他用户有所帮助。从GET改为POST解决了这个问题!此外,我还实现了id提示。谢谢你的帮助!