tags:

views:

39

answers:

3

I have 2 forms that share a submit button

("#sbtBtn").click(function() {
          if($("input[name=license_code]").val()) {      //check if #retUser has a value
            $("#formOne").submit();
          } else if ($("input[name=referred_by_text]").val() || $("input[name=broker_text]").val() || $("input[name=email1]").val()) {
            $("#formTwo").submit();
          }

    });

for "#formOne" I am trying to use jquery's getJSON function to use a script cross domain, its not working.

$("#formOne").validate({
            errorElement: "em",
            errorPlacement: function(error, element) {
                error.appendTo( element.parent("li"));
            },
            submitHandler: function(form) {
                var dataString = $(form).serialize();
                $.getJSON("http://www.domain.com/sugar/NT7Lead2.php?data=" + escape($(this).serialize()) + "&callback=?", function(data) {
                                                                                                                                                $("#results").html(data);
                                                                                                                                                });
            return false;
            },
            rules: {
                    license_code: {
                    minlength: 3,
                    maxlength: 39
                }
            },

            messages: {
                license_code: {
                    minlength: "Your License be at Least 3 Characters Including Dashes",
                    maxlength: "Your License Key Cannot Be More Than 39 Characters Including Dashes"
                }
            }
    });

When I view in firebug, the data is being returned from the script but its not being added to "#results". Is there anything obviously wrong here? Also do I need to include the script in the form action since its in the JSON function? here's the html

<div class="purchaseFormContain" id="currentUser">
                    <div class="purchaseTH form" id="formOneTH"><h3>Current Users</h3></div>
                    <form method="post" name="formOne" id="formOne">
                        <ul class="features">
                            <li><label for="license_code">Enter Your License Key Here</label></li>
                            <li><input type="text" name="license_code" /></li>
                        </ul>
                    </form>
                    <div class="clear"></div>
                    <div id="results"></div>
                <!--/retUser purchaseFormContain --></div>

pls help! thx

A: 

"You have to see if the site in question supports JSONP" - see Cross domain ajax response failing.

Bermo
I don't think it does. when I entered the form processor script url + callback=foobar it displayed the message error message from the script on the page you get if you fail validation, not the callback
Dirty Bird Design
+1  A: 

Beyond JSONP if you have any experience with server-side languages you could pretty easily create a little app locally that fetches the response for you.

e.g. in Java you have a servlet that takes your the desired parameters, the servlet makes the request and then returns the response.

Jared
A: 

Try getting a sample of the response. It should be JSON. Try to check how you are accessing to the response. I had some problems with that too. Also, it's a great idea use a server side script. If you use php, try with cURL. It's easy

chepe263
I have used cURL on other forms on this site, but they just connect to a web service. This has to interact with a database, which Im having trouble closing the connection. Ill post the code for that in another topic. thanks!
Dirty Bird Design