I'm really new to web programming. I'm trying to make a form post and get the callback.
I'm trying to use this plugin here: http://malsup.com/jquery/form/#ajaxSubmit
But when I call the:
$("#my_form").ajaxSubmit(options); Nothing happens..
What I have done so far:
I have this form
<form method="post" id="my_form" action="record.php" enctype="multipart/form-data" >
// stuff inside..
<input type="button" id = "recordDatabase" value="Rcord on Database" />
And I have this script:
var options =
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
alert('About to submit: \n\n');
Finally my two functions are:
function showRequest(formData, jqForm, options)
// formData is an array; here we use $.param to convert it to a string to display it
var queryString = $.param(formData);
alert('About to submit: \n\n' + queryString);
function showResponse(responseText, statusText, xhr, $form)
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
Im doing exactly like the example on the site(http://malsup.com/jquery/form/#ajaxSubmit), but it doesnt work.
Any idea what's wrong?
I don't think you can hotlink to the jQuery plugin on Git. Try downloading the plugin and saving it as a JS file in your application web root.
It looks like you are not referencing your scripts correctly. According to your comment, you have included your scripts like this:
<script src="ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="localhost/js/jqueryPlugin.js"></script>
These are relative URLs. The browser will request the resources from your site by tacking on those relative URLs to the end of the current directory.
Suppose this page is at
http://localhost/myapp/mypage.html. The browser will look for your script files at:
These URLs probably don't exist. Maybe your browser is smart enough to recognise "ajax.googleapis.com" as a domain name and request the data from the domain, but it's less likely that it will recognize "localhost" as a domain.
// to the beginning of the URL. This is a "Schema-relative URL" and will use either http or https depending on what the current page is using. We use these kind of URLs to avoid security prompts warning users that some of the content on the page is not secure. Your scripts would then look like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//localhost/js/jqueryPlugin.js"></script>