1

Possible Duplicate:
Validating url with jQuery without the validate-plugin?

is there any jquery method to check a url is valid?

or can jquery get http header? some code method like this.

js code:

$('#submit').click(function(){
  var url = $('#url').val();
  // check a url is valid?
});

html code:

<input id="url" name="url" type="text">
<input type="submit" name="submit" id="submit" value="submit" />
Community
  • 1
  • 1
cj333
  • 2,547
  • 20
  • 67
  • 110
  • 1
    http://stackoverflow.com/questions/2723140/validating-url-with-jquery-without-the-validate-plugin – kpotehin Apr 13 '12 at 20:10

2 Answers2

2

Here is some information that I found:

        <script type="text/javascript">
        $(document).ready(function() {
           $("#commentForm").validate({
              rules: {
                 field: {
                    required: true,
                    url : true
                 }
              }
           });
        });
        </script>

Source of information

Another person already answered this on stackoverflow

Link to jQuery URL Method

Community
  • 1
  • 1
Quest4Answers
  • 88
  • 1
  • 8
0

Well, if I'm getting you right, you can do a $.ajax() to the url and see the response status codes.

You can set different methods for the statuses you get.

Check this link: http://api.jquery.com/jQuery.ajax/

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • 3
    `$.ajax` must obey the [same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy). This will only work if the URLs are to the same domain as the page. – gen_Eric Apr 13 '12 at 20:18
  • Yes, same domain policy applies, unless CORS is enabled on target server. Another option is to send AJAX request to your server which makes http request and returnes result to client – Maksym Kozlenko Sep 23 '12 at 23:12