Jump to content

Update Firstname & Lastname with $ajax & JSON


Shurek

Recommended Posts

Dear reader,

 

I am trying to update Firstname & Lastname with this script:

 

TPL:

<form action="{$link->getPageLink('address', true,"back=order-opc")|escape:'html':'UTF-8'}" method="post" class="std" id="add_address">
<input type="hidden" name="id_address" value="513" id="id_address">
<fieldset>
			<div class="required form-group">
            		<label for="firstname" class="required">
                        Voornaam
                    </label>
                    <input class="is_required validate form-control" data-validate="isName" type="text" id="firstname" name="firstname" value="" />
                </div>
                <div class="required form-group">
                    <label for="lastname" class="required">
                        Achternaam
                    </label>
                    <input class="is_required validate form-control" data-validate="isName" type="text" name="lastname" id="lastname" value="" />
                    
			
                    <button type="submit" name="submitAddress" id="submitAddress" class="twin-buttons twin-green-button twin-identity-save-button twin-float-left">
                        <span>bevestig</span>
                    </button>
                </div>
                
		</fieldset>
	</form>

and also this ajax request:

{literal}
<script type="text/javascript">
$(document).ready(function()
{
	$('#add_address').submit(function(e)
	{
		var formObj = $(this);
        var formURL = formObj.attr("action");
		
		//e.preventDefault();
		console.log('step-3');
		if(window.FormData !== undefined)  // for HTML5 browsers
        {
        
            var formData = new FormData(this);
			
            $.ajax({
                url         : formURL+$('#id_address').val(),
                dataType    : "json",
                type        : "POST",
                data        : formData,
                contentType : false,
                cache       : false,
                processData : false,
                success: function(data)
                {
                	$('#add_address').hide('slow');
                	//$('#address').after(data);
					$('.twin-email-updated').show('slow');
                    
                },
                error: function(jqXHR, textStatus, errorThrown) 
                {
					alert('echt een error');
                    alert(errorThrown);
                }           
           });
            e.preventDefault();
       }
       else  //for olden browsers
        {
            
        
        }
	})

})
</script>
{/literal}

But all of the time I get an error: Not Found

 

I am sure the id of the address is 513 but the error is still Not Found.

 

Maybe somebody knows what i am doing wrong?

 

Best regards,

 

Sjoerd

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...