jQuery how to refer to the directory $.post()

349
November 26, 2016, at 12:39 PM

welcome how to file script.js refer to index.php?

in script.js:

$.post('../php/index.php', {data});

structure directory:

js/
  script.js
php/
  index.php
index.html

return me in console:

404 (Not Found) Cannot POST /php/index.php

Answer 1

Just use the file location in full, like:

$.post('http://www.example.com/directory/php/index.php', {data});
Answer 2

The url in your javascript has to be relative to the current active url in the web browser. The best way to solve this for you is to use a absolute path. Like this:

$.post('/php/index.php', {data});
Rent Charter Buses Company
READ ALSO
HTML,CSS,JavaScript pop up issue

HTML,CSS,JavaScript pop up issue

I want a popup to be displayed in a particular format after clickon a button

315
Irregular thickness of SVG polygon edges

Irregular thickness of SVG polygon edges

I have a Voronoi treemap and wanted to change the thickness of the polygons on mouseover

293
Dynamically get Rails DB queries

Dynamically get Rails DB queries

Is there a way to dynamically get a db result in rails? FOr example, I have all of cities indexed with an idI want to sent the id to the view given a city name, like this Javascript method (I know this doesn't work

346
Highcharts chart creation using d3.csv

Highcharts chart creation using d3.csv

This is in continued to my question here

407