• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 825
  • Last Modified:

jQuery ajax post data to aspx webpage

Hello Experts,

I am building an app in xCode with phonegap. Currently I am using ajax to load data from a remote source (Display.aspx) and that is working perfect. However I want to then post data to my Input.aspx page. I have the sites whitelisted so crossdomain issues should not be there.

I also tried the code on the same server to verify it is not a crossdomain issue.

Right now the form that adds data to my database is a basic page with text inputs.

Now I have a third page (which eventually will be an iOS app) that I am trying to post from. Can I not just use ajax to submit directly to the Input.aspx page, or do I have to have some kind of web service?

I think I need a clear example of how ajax can submit data to a remote website (remember crossdomain should not be an issue as it is an app).

I think I don't get how the aspx page should be built? Does it need specific code for the ajax or can it just be a generic page with a form that submits?

Any help is greatly appreciated.
0
STRAC
Asked:
STRAC
  • 2
1 Solution
 
Kyle HamiltonData ScientistCommented:
If i understand correctly, you want the input from one page to poulate a form on another page?

You can use javascript by passing the values via a query string and and reading them in using javascript on the rusulting page.

Your form on page 1 uses GET. This will pass the name field to the resultsPage.html
<form name="myForm" id="myForm" method="GET" action="resultsPage.html">
<input type="text" name="first_name"/>
<input type="submit" value="Click here to continue" class="submit">
</form>

Open in new window


On the resultPage.html you will need a script that reads the url. The form field names must match the form from the previous page:
<form name="myForm">
<input type="text" name="first_name"/>
</form>
<script type="text/javascript" language="JavaScript">
    <!-- Copyright 2006 Bontrager Connection, LLC
    function FillForm() {
        // Specify form's name between the quotes on next line.
        var FormName = "myForm";
        var questionlocation = location.href.indexOf('?');
        if(questionlocation < 0) { return; }
        var q = location.href.substr(questionlocation + 1);
        var list = q.split('&');
        for(var i = 0; i < list.length; i++) {
            var kv = list[i].split('=');
            if(! eval('document.'+FormName+'.'+kv[0])) { continue; }
            kv[1] = unescape(kv[1]);
            if(kv[1].indexOf('"') > -1) {
                var re = /"/g;
                kv[1] = kv[1].replace(re,'\\"');
            }
            eval('document.'+FormName+'.'+kv[0]+'.value="'+kv[1]+'"');
        }
    }
    FillForm();
    //-->
</script>

Open in new window

0
 
STRACAuthor Commented:
Valid solution, with a few limitations. Thanks!
0
 
Kyle HamiltonData ScientistCommented:
no prob. What limitations do you mean?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now