简体   繁体   中英

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. 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. 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. I don't have much love for javascript, especially Jquery, so any help would be greatly appreciated.

您应该做的第一件事是关闭顶部的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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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