Ajax GET does not work

Hello,

i have ajax that post URL.

What i want to do is switch months inside a modal
it works in simple php file but does not work in my modal :frowning:

My script:

    <script>
		$('#submit_formz').click(function(e){
		  
			e.preventDefault(); // Prevent Default Submission
		  
			$.ajax({
		 url: 'page_machinery_planning_child',
		 type: 'GET',
		 data: $(this).serialize(), // it will serialize the form data
				dataType: 'html'
			})
			
			.done(function(data){
			 $('#form-content').fadeOut('fast', function(){
				  $('#form-content').fadeIn('fast').html(data);
				  setTimeout(
				  function(){
				  $('.ui.modal').modal('refresh');
				  }, 1);
				});
			})
			.fail(function(){
		 alert('Ajax Submit Failed ...'); 
			});
		});
    </script>

PHP:


if(!$date){$date=date('Y-m-d');}else{$date=$date;}
$next_month = date('Y-m-d', strtotime("+1 months", strtotime(date('Y-m-01',strtotime($date)))));
$prev_month = date('Y-m-d', strtotime("-1 months", strtotime(date('Y-m-01',strtotime($date)))));
echo '
<table><tr>
<td align="right" id="submit_formz2"><a href="page_machinery_planning_child.php?date='.$next_month.'"> >> </a>
</tr></table>';

Any tips for whats wrong?

Thanks

Set the correct directory at url property eg.page_machinery_planning_child.html or page_machinery_planning_child.php

I think that is not the issue as i have htaccess removing file extension php.
I also tried your idea but that is the same.

Add the extension at file and retry.

i did it nothing changed

What errors do you have?

none it just get back to the same place in modal not changing date in url

I think that the problem is in your php file.I mean that the php code doesn’t produce an html code.I test your code in my IDE and it works.Can you post the php code at page_machinery_planning_child?

done but theres nothing that could be wrong i think

Did you find what is cause?

nope

Hello!

If you are clicking on a submit button, you won’t get the data with $(this).serialize()
Instead, you should add a submit event handler to the form.

Like this:

This way, you will GET the data to the server.

1 Like

Looks nice thanks :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.