简体   繁体   English

Ajax在页面加载时提交

[英]Ajax submission on page load

I'm trying to create a test script for a small little website I'm doing, and it requires a lot of troubleshooting with this particular form. 我正在尝试为我正在做的一个小型网站创建测试脚本,并且需要使用此特定表单进行大量的故障排除。 In order to get a response, I need to fill out 5 step form wizard and then wait for the results. 为了获得响应,我需要填写5步骤表单向导,然后等待结果。 I've been trying to create a small little script I can use on a seperate page to test my php functions in a heartbeat. 我一直在尝试创建一个小的脚本,可以在单独的页面上使用它来检测我的php函数。 Here is what I have so far, and it doesn't seem to even post to the page. 这是我到目前为止的内容,它似乎甚至都没有发布到页面上。

<div id="response"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var data = {
        console: "playstation",
        game: "FIFA14",
        coinamount: "10000",
        team: "Some Team Name",
        league: "Some League Name",
        player: "Some Player Name",
        quality: "Silver",
        chemistry: "Basic",
        position: "CAM",
        customername: "Joey Small",
        customeremail: "jsmall@email.com",
        customerphonenumber: "23454343534",
        payment: "pp"
    }
$.ajax({
    type: "POST",
    url: "order.php",
    data: data,
    cache: false,
    contentType: false,
    processData: false,
    success:  function(data){
        $("#response").html(data);
    }
});
});
</script>

I'm inspecting the network data in my browser, and it is not sending to order.php. 我正在浏览器中检查网络数据,它没有发送到order.php。 I don't have much love for javascript, especially Jquery, so any help would be greatly appreciated. 我对javascript尤其是Jquery不太感兴趣,因此任何帮助将不胜感激。

您应该做的第一件事是关闭顶部的Jquery上的script标签

Ok, so the additional options added on to the end are what is making the script not submit. 好的,所以最后添加的其他选项使脚本无法提交。

$.ajax({
    type: "POST",
    url: "order.php",
    data: data,
    success:  function(data){
        //alert("---"+data);
        $("#response").html(data);
    }
});

That works correctly. 可以正常工作。 Daedalus's comment got me to thinking about the additional tags, and how they are not needed. 达达洛斯(Daedalus)的评论使我开始思考其他标签以及如何不需要它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM