Home I'm trying to use Ajax to send data to another page
Reply: 0

I'm trying to use Ajax to send data to another page

user3596 Published in April 21, 2018, 3:28 pm

Ok so it's a bit complex, and I don't understand why this is not working. I'm trying to make a page where you have some textbox and dropbox list, and a datagrid using easyui (that part works well). What I am trying to do is that when I'm selectionning something in one dropbox list, I'm doing 2 actions : Sending some info to another php page to write in a database, and changing the columns of my datagrid. This almost works. I write in the database, but every values are null, and my columns changes.

So, what I have for my droplist is something like :

    function changecolumn(){
    //those are my data from textbox/dropbox list
    		var headerData = {
    			'date'      : $('input[name=date]').val(),
    			'sunset'    : document.getElementById('sunset').value,
    			'sunrise'    : $('input[name=sunrise]').val(),
    			'moonset'    : $('input[name=moonset]').val(),
    			'moonrise'    : $('input[name=moonrise]').val(),
    			'moonphase'    : $('input[name=moonphase]').val(),
    			'instrument'    : selectedInstrument,
    			'obsname'    : $('input[name=obsname]').val(),
    			'astroresp'    : $('input[name=astroresp]').val(),
    			'techname'    : $('input[name=techname]').val()
    //Trying to uses ajax here.    
                              data: "headerData",
                              //data: {sunset : document.getElementById('sunset').value, sunrise : document.getElementById('sunrise').value, moonset : document.getElementById('moonset').value, moonrise : document.getElementById('moonrise').value, moonphase : document.getElementById('moonphase').value, instrument : selectedInstrument, obsname : document.getElementById('obsname').value, astroresp : document.getElementById('astroresp').value, techname : document.getElementById('techname').value  },
    			   success: function(data) {
                    alert("Data was succesfully captured"); },
                // using the done promise callback
                .done(function(data) {

                    // log data to the console so we can see

                    // here we will handle errors and validation messages

    		var listInstrument = document.getElementById("instrument");
    		var selectedInstrument = listInstrument.options[listInstrument.selectedIndex].text;
    		if(selectedInstrument == 'one'){
            //this part is working
    		else { 
        //this part is working
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="instrument" name="instrument" onchange="changecolumn()">
    <option> one
    <option> two
    <option> three

And in my PHP page, I uses : $sunrise = $_POST['sunrise']; to try to get the data, but everything is empty..

I'm not sure what is wrong, anyone have any idea?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302166 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO