Hessius
Hessius

Reputation: 1404

Detect successful html form submission using POST to cross-domain script from PhoneGap, mobile jQuery app

I'm making a PhoneGap mobile jQuery-based iOS app for evaluating courses at my uni. The university provides a course evaluation platform that uses a regular html-form with method="POST".

As the script belongs to and is hosted by my uni I cannot edit it nor read it.

<form action="http://example.com/script/kurt2/receive.php" method="post" target="result" onsubmit="" id="klinikkurt">
<input type="hidden" name="id" value="4136" />
<input type="range" name="q1" value="" min="1" max="6"  data-track-theme="d" data-theme="d"/>
</form>

On successful submission the script redirects to a thank you-page, this renders the app useless. Adding a target to the form and a hidden iframe keeps the app usable on submission.

I would like to display a thank you message and reset the form in the app upon successful submission the problem (and my question) is that I don't know how to detect a successful form submission.

I've tried using an onLoad event on the iframe, and while this will execute javascript on successful submission it will also execute the function on initial load.

UPDATE

Per Elijah's suggestion I've been trying (unsuccessfully) to achieve this using jQuery's .ajax
This is my code:
HTML: As above but I've removed the action-attribute on the form.

Javascript:

$("#klinikkurt").submit(function() {
var dataString = $("#klinikkurt").serialize();
$.ajax({
    url: 'https://doit.medfarm.uu.se/script/kurt2/receive.php',
    type: "POST",
    data: dataString,
    success: function() {
        $('#kk').load('index.html');
    }
});
return false;
});

On submit nothing happens but a refresh.

Upvotes: 1

Views: 2016

Answers (2)

Severin Sigismund
Severin Sigismund

Reputation: 1

Social bookmarking sites like Digg and Reddit let the users decide the main content of the site by voting on content that the users like. They use AJAX to handle all of the voting, so that the users are able to voice their opinions on a number of stories quickly and easily.

Upvotes: 0

elijah
elijah

Reputation: 2924

how about using AJAX to submit the form content? This would allow you to handle the result of the HTTP request in your JS instead of the browser handling it directly...

Upvotes: 3

Related Questions