Welcome Guest, Not a member yet? Register   Sign In
JQuery Validation
#11

[eluser]syntax error[/eluser]
Point taken, in any case, i can't see how my example is difficult to get your head around. With the apparent new jquery validation, you still need to get codeiginiter to ouput xml responses
#12

[eluser]nmweb[/eluser]
I haven't really looked at the code but wouldn't it be easier to return json? Php has functions to encode stuff in json and jQuery's Ajax functions also can work with it.
#13

[eluser]syntax error[/eluser]
Well returning JSON or XML, Jquery makes it very easy to work with both. I'm not too clued up on which would be better.
#14

[eluser]Mark van der Walle[/eluser]
jQuery has a plugin for ajaxing forms (check www.visualjquery.com for a reference):
Code:
$('#myForm').ajaxSubmit(function(data) {
    alert('Form submit succeeded! Server returned: ' + data);
});

In the function you would just use your normal handling that you would do.
#15

[eluser]syntax error[/eluser]
Indeed the JQuery form plugin is very useful.
#16

[eluser]RobbieL[/eluser]
Cheers guys. I've been having a look at the JQuery plugins for forms, especially ajaxSubmit. I don't know why I'm having trouble understanding it, maybe it's because it seems just to simple. The example provided says:

Code:
var options = {
    url: myXmlUrl.php,
    dataType: 'xml',
    success: function(responseXML) {
       // responseXML is XML document object
       var data = $('myElement', responseXML).text();
    }
};
$('#myForm').ajaxSubmit(options);

Have I got this right? When the form with the ID of "myForm" is submitted, it runs the options in the variable. Taking into consideration I want to make use of the CI validation, the URL would be the path to my controller that deals with the validation, dataType is simply saying the data returned from the server will be in XML and if everything is successful, run a function that spits out the data from the XML into a DIV with the ID of myElement.

Also, since I began messing around with JQuery, I keep seeing "JSON" popping up. What exactly is the benefit of using JSON over XML?
#17

[eluser]Mark van der Walle[/eluser]
First to answer your last question: JSON is alot faster for javascript so if your url is only used for javascript json is the way to go.

Then the first question. You almost got it right except that this:
Code:
success: function(responseXML) {
   // responseXML is XML document object
   var data = $('myElement', responseXML).text();
}
will take part of the XML and put it into the data variable. Where the XML is something like:
<myElement>The contents that are being put into the data variable</myElement>
#18

[eluser]xwero[/eluser]
json has a shorter notation than xml. an ajaxian post about the difference

edit : I've seen there is not much information about the formats so here is an article about different ajax responses on quirksblog
#19

[eluser]syntax error[/eluser]
Also remember, if you do decide to go with XML response, ensure your headers are set correctly serverside:
Code:
header('Content-type: text/xml');




Theme © iAndrew 2016 - Forum software by © MyBB